<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>authorized_keys &#8211; 記下來</title>
	<atom:link href="https://noter.tw/tag/authorized_keys/feed/" rel="self" type="application/rss+xml" />
	<link>https://noter.tw</link>
	<description>一路上踩到的坑、遇到的問題，一點一滴記下來，希望能幫助到需要的人~</description>
	<lastBuildDate>Wed, 03 Jan 2024 02:35:06 +0000</lastBuildDate>
	<language>zh-TW</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.6.3</generator>

<image>
	<url>https://noter.tw/wp-content/uploads/cropped-old-1130742_1920-1-32x32.jpg</url>
	<title>authorized_keys &#8211; 記下來</title>
	<link>https://noter.tw</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>登入 ssh 免輸入帳號密碼</title>
		<link>https://noter.tw/278/%e7%99%bb%e5%85%a5-ssh-%e5%85%8d%e8%bc%b8%e5%85%a5%e5%b8%b3%e8%99%9f%e5%af%86%e7%a2%bc/</link>
					<comments>https://noter.tw/278/%e7%99%bb%e5%85%a5-ssh-%e5%85%8d%e8%bc%b8%e5%85%a5%e5%b8%b3%e8%99%9f%e5%af%86%e7%a2%bc/#respond</comments>
		
		<dc:creator><![CDATA[黃小蛙]]></dc:creator>
		<pubDate>Sun, 03 Jun 2018 05:02:50 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[技術相關]]></category>
		<category><![CDATA[ssh-keygen]]></category>
		<category><![CDATA[免密碼]]></category>
		<category><![CDATA[ssh key]]></category>
		<category><![CDATA[ssh 免輸入密碼]]></category>
		<category><![CDATA[authorized_keys]]></category>
		<category><![CDATA[ssh 直接登入]]></category>
		<category><![CDATA[id_rsa]]></category>
		<category><![CDATA[SSH 指定金鑰]]></category>
		<category><![CDATA[PieTTYTY]]></category>
		<category><![CDATA[SSH 允許金鑰]]></category>
		<category><![CDATA[PuTTY]]></category>
		<category><![CDATA[PuTTYgen]]></category>
		<category><![CDATA[ssh]]></category>
		<guid isPermaLink="false">https://noter.tw/?p=278</guid>

					<description><![CDATA[<p>每次需要產生公私鑰的時候總是忘記，記錄在這邊，同時給有需要的人！ （2019-11-01 補充：這篇寫得很詳細，如果有不清楚的地方可以參考） 從 Windows 登入 Linux 小蛙在家大多使用 W&#46;&#46;&#46;</p>
<p>這篇文章 <a rel="nofollow" href="https://noter.tw/278/%e7%99%bb%e5%85%a5-ssh-%e5%85%8d%e8%bc%b8%e5%85%a5%e5%b8%b3%e8%99%9f%e5%af%86%e7%a2%bc/" data-wpel-link="internal">登入 ssh 免輸入帳號密碼</a> 最早出現於 <a rel="nofollow" href="https://noter.tw" data-wpel-link="internal">記下來</a>。</p>
]]></description>
										<content:encoded><![CDATA[
<p> 每次需要產生公私鑰的時候總是忘記，記錄在這邊，同時給有需要的人！ （2019-11-01 補充：<a href="https://devops.ionos.com/tutorials/use-ssh-keys-with-putty-on-windows/" target="_blank" rel="noreferrer noopener nofollow external" aria-label="這篇 (在新分頁中開啟)" data-wpel-link="external" class="wpel-icon-right">這篇<span class="wpel-icon wpel-image wpel-icon-6"></span></a>寫得很詳細，如果有不清楚的地方可以參考）</p>



<span id="more-278"></span>



<h2 class="para wp-block-heading">從 Windows 登入 Linux </h2>



<p>

小蛙在家大多使用 Windows 的環境，當需要幫忙管理朋友的伺服器，才去翻東翻西去找出密碼來，這時候就可以在要登入管理的 Linux 系統下設定好相對應的公鑰，當小蛙的 Windows 拿著私鑰來連線的時候，公鑰跟私鑰搭配成一組就可以免輸入密碼登入囉！

</p>



<h3 class="para wp-block-heading">在 Windows 電腦上取得公私鑰步驟</h3>



<p>1. 下載 <a href="http://bcc16.ncu.edu.tw/6/putty/puttygen.html" target="_blank" rel="noreferrer noopener nofollow external" data-wpel-link="external" class="wpel-icon-right">PuTTYgen<span class="wpel-icon wpel-image wpel-icon-6"></span></a></p>



<p>2. 開啟後可基本按照該網頁的操作進行，大概是 (a) 設定 SSH-2 RSA  (b) 長度小蛙設定 2048  (c) 點選 Generate (小蛙後來使用 MobaXterm 裡面有一個類似 PuTTYgen 的工具 MobaKeyGen，使用上大同小異)</p>


<div class="wp-block-image">
<figure class="aligncenter size-large is-resized"><img fetchpriority="high" decoding="async" src="https://lh3.googleusercontent.com/pw/AL9nZEUVEIbskrddj_V3MycO_12NZ_yBjbtSfkYZyDagiBhIP1xpg-ssDDeDEIzVYCPGpctplCous1VBcaIXfOZ4U-gtN5dIxhJkYZYjmACIHWGJ7yYOUYvcHatz7v5cATPIZb-VyWyaBsEsULoHDkOj1tTT=w958-h894-no?authuser=2" alt="AL9nZEUVEIbskrddj V3MycO 12NZ yBjbtSfkYZyDagiBhIP1xpg ssDDeDEIzVYCPGpctplCous1VBcaIXfOZ4U gtN5dIxhJkYZYjmACIHWGJ7yYOUYvcHatz7v5cATPIZb VyWyaBsEsULoHDkOj1tTT=w958 h894 no?authuser=2 登入 ssh 免輸入帳號密碼" width="479" height="447" title="登入 ssh 免輸入帳號密碼"></figure></div>


<p>3. 此時在進度條下方滑鼠動來動去，一開始小蛙不知道，想說怎麼進度條都不會動 &#8230;</p>


<div class="wp-block-image">
<figure class="aligncenter size-large is-resized"><img decoding="async" src="https://lh3.googleusercontent.com/pw/AL9nZEWEl0WsCBdMe-1TdcH4g3rq6WILjUbFhQ5B5nqy-rnfQD7cJbDokMmza7GvIPktJlMxx9JuQL7Cnnkr1x9nY6AN4Xl9pHVIpHywp-PPhAbfP-zQbw7fVJpp5yAAMJUEMvfK9t8prAsW7pvidb0OlUcv=w477-h446-no?authuser=2" alt="AL9nZEWEl0WsCBdMe 1TdcH4g3rq6WILjUbFhQ5B5nqy rnfQD7cJbDokMmza7GvIPktJlMxx9JuQL7Cnnkr1x9nY6AN4Xl9pHVIpHywp PPhAbfP zQbw7fVJpp5yAAMJUEMvfK9t8prAsW7pvidb0OlUcv=w477 h446 no?authuser=2 登入 ssh 免輸入帳號密碼" width="358" height="335" title="登入 ssh 免輸入帳號密碼"></figure></div>


<p>4. 複製產生出來的 Pubkey</p>



<p>5. 如果要登入不輸入密碼，Key passphrase 留空白，這裡也可以把所有自己的 key 都設定成同一個密碼，這樣也可以達到所有機器用同一個密碼搭配 key 登入，不再需要記哪台機器是哪個密碼，小蛙是懶惰，不想輸入密碼 &#8230;</p>



<p>6. key comment 可以隨便打，自己可以認出是什麼並且管理就好</p>



<p>7. Save public key 及 Save private key，務必好好保管，如果私鑰掉了，就沒辦法跟公鑰搭成一對囉</p>


<div class="wp-block-image">
<figure class="aligncenter size-large is-resized"><img decoding="async" src="https://lh3.googleusercontent.com/pw/AL9nZEXUCd7H22scM89sjeWKRBuOTpV5WowL9QOImMSmyUm_3VkC3sqQX5tQXHA6YvvFnofgF80iFTAkgV-u5eMITGrcgxNvTMu3JWuYnlncho2H0Qt4vjvvVymeINnLCMyfe0ab9Nfd_EFsoBsALs6GbGql=w958-h894-no?authuser=2" alt="AL9nZEXUCd7H22scM89sjeWKRBuOTpV5WowL9QOImMSmyUm 3VkC3sqQX5tQXHA6YvvFnofgF80iFTAkgV u5eMITGrcgxNvTMu3JWuYnlncho2H0Qt4vjvvVymeINnLCMyfe0ab9Nfd EFsoBsALs6GbGql=w958 h894 no?authuser=2 登入 ssh 免輸入帳號密碼" width="479" height="447" title="登入 ssh 免輸入帳號密碼"></figure></div>


<h3 class="para wp-block-heading">Linux 設定允許登入的金鑰 </h3>



<ol class="my-li bg-darkblue wp-block-list"><li>先遠端登入 Linux 系統，小蛙的是 Ubuntu，不過應該都差不多</li><li>編輯登入目錄下的設定檔，如果沒有該檔案的話，可直接新建一個 vim ~/.ssh/authorized_keys</li><li>將上面複製的公鑰，貼在檔案中，要注意每一行為一個金鑰，儲存後離開</li></ol>



<h3 class="para wp-block-heading">Windows 設定使用私鑰連線 &#8211; PieTTY</h3>



<ol class="my-li bg-darkblue wp-block-list"><li>開啟 <a href="https://sites.google.com/view/pietty-project/home" target="_blank" rel="noreferrer noopener nofollow external" data-wpel-link="external" class="wpel-icon-right">PieTTY<span class="wpel-icon wpel-image wpel-icon-6"></span></a>&nbsp;或是 <a href="https://www.putty.org/" target="_blank" rel="noreferrer noopener nofollow external" data-wpel-link="external" class="wpel-icon-right">PuTTY<span class="wpel-icon wpel-image wpel-icon-6"></span></a>&nbsp;(以下小蛙以 PieTTY 作為範例)</li><li>點選 PuTTY 模式，先設定好要連線的 IP, Port，接著在 Saved Sessions 填入要儲存的名字，以後可以直接選，不用每次都要設定</li><li>找到 Connection -&gt; Data -&gt; Login details: Auto-login username，填入 Linux 登入的帳號</li><li>找到 Connection -&gt; SSH -&gt; Auth -&gt; 把 Attempt authentication using Pasgeant 及 Attempt &#8220;keyboard-interactive&#8221; auth (SSH-2) 打勾</li><li>接續點選 Browse&#8230; 選取上面產生出來的 Private key</li><li>回到 Session 頁籤，點選右方 Save，把剛剛的設定存好</li><li>點選 Open 就可以直接連線到 Linux 主機囉</li></ol>



<h3 class="para wp-block-heading">Windows 設定使用私鑰連線 &#8211; FileZilla</h3>



<ol class="my-li bg-darkblue wp-block-list"><li>開啟 FileZilla -&gt; 檔案 -&gt; 站台管理員</li><li>新增站台，右邊「一般」，協定「SFTP」，登入形式改成「金鑰檔案」，這裡要選擇剛剛產生的私鑰，其他主機名稱跟使用者照自己的設定輸入</li><li>直接連線就可以囉！</li></ol>



<h2 class="para wp-block-heading">Linux 連線到 Linux</h2>



<p>首先必須在要連線的 Linux client 建立一組金鑰，分別會是公鑰<code>id_rsa.pub</code>及私鑰<code>id_rsa</code>，必須要把這組金鑰保存好。 </p>



<h3 class="para wp-block-heading">產生金鑰 </h3>



<pre class="wp-block-preformatted wp-block-syntaxhighlighter-code">ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 直接按 Enter
Enter passphrase (empty for no passphrase): 直接按 Enter
Enter same passphrase again: 直接按 Enter
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
......
The key's randomart image is:
......</pre>



<h3 class="para wp-block-heading">設置公鑰 </h3>



<p>把公鑰設置到要連線的主機信任清單內，可以使用上面的方法 vim ~/.ssh/authorized_keys，或是從<a rel="noreferrer noopener nofollow external" href="https://gwokae.mewggle.com/wordpress/2010/08/%E8%B6%85%E6%98%93-%E5%85%A9%E8%A1%8C%E6%8C%87%E4%BB%A4%E6%90%9E%E5%AE%9A-linux-ssh%E7%99%BB%E5%85%A5%E5%85%8D%E5%AF%86%E7%A2%BC/#step1-key-pair-gen" target="_blank" data-wpel-link="external" class="wpel-icon-right">這邊<span class="wpel-icon wpel-image wpel-icon-6"></span></a>看到的很方便的方法，直接從要連線的這台設定即可</p>



<pre class="wp-block-preformatted wp-block-syntaxhighlighter-code">cat ~/.ssh/id_rsa.pub | ssh root@your_id_address "cat &gt;&gt; ~/.ssh/authorized_keys"
# 將 id_rsa.pub 的內容透過 ssh 傳到遠端並且放進 authorized_keys 裡面</pre>



<h2 class="para wp-block-heading">其他</h2>



<h3 class="para wp-block-heading">使用特定金鑰</h3>



<p>當下 ssh xxx@x.x.x.x 的時候，會預設使用家目錄下的 id_rsa 進行連線，但有時候小蛙必須要幫朋友用別的金鑰測試，這時候就可以透過 -i 這個參數來設定</p>



<pre class="wp-block-preformatted wp-block-syntaxhighlighter-code">xx:~ hans$ ssh -i Desktop/private_key_mac xxx@x.x.x.x</pre>



<h3 class="para wp-block-heading">權限錯誤問題</h3>



<p>小蛙在使用朋友給的金鑰時，發生以下錯誤</p>



<pre class="wp-block-preformatted wp-block-syntaxhighlighter-code">xx:~ hans$ ssh -i Desktop/private_key_mac xxx@x.x.x.x
Warning: Permanently added 'x.x.x.x' (ECDSA) to the list of known hosts.
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: UNPROTECTED PRIVATE KEY FILE! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0644 for 'Desktop/private_key_mac' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
Load key "Desktop/private_key_mac": bad permissions</pre>



<p>查了一下確切需要的權限只要 400 就可以</p>



<pre class="wp-block-preformatted wp-block-syntaxhighlighter-code">chmod 400 私鑰</pre>



<h2 class="para wp-block-heading">參考資料 </h2>



<ol class="my-li bg-darkblue wp-block-list"><li><a href="http://bcc16.ncu.edu.tw/6/putty/puttygen.html" target="_blank" rel="noreferrer noopener nofollow external" data-wpel-link="external" class="wpel-icon-right">PuTTYgen<span class="wpel-icon wpel-image wpel-icon-6"></span></a></li><li><a href="https://sites.google.com/view/pietty-project/home" target="_blank" rel="noreferrer noopener nofollow external" data-wpel-link="external" class="wpel-icon-right">PieTTY<span class="wpel-icon wpel-image wpel-icon-6"></span></a></li><li><a href="https://www.putty.org/" target="_blank" rel="noreferrer noopener nofollow external" data-wpel-link="external" class="wpel-icon-right">PuTTY<span class="wpel-icon wpel-image wpel-icon-6"></span></a></li></ol>
<p>這篇文章 <a rel="nofollow" href="https://noter.tw/278/%e7%99%bb%e5%85%a5-ssh-%e5%85%8d%e8%bc%b8%e5%85%a5%e5%b8%b3%e8%99%9f%e5%af%86%e7%a2%bc/" data-wpel-link="internal">登入 ssh 免輸入帳號密碼</a> 最早出現於 <a rel="nofollow" href="https://noter.tw" data-wpel-link="internal">記下來</a>。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://noter.tw/278/%e7%99%bb%e5%85%a5-ssh-%e5%85%8d%e8%bc%b8%e5%85%a5%e5%b8%b3%e8%99%9f%e5%af%86%e7%a2%bc/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
