<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Ubuntu 18.04　ssh key的配置以及免密登录]]></title><description><![CDATA[<p dir="auto"><a href="https://www.digitalocean.com/community/tutorials/how-to-set-up-ssh-keys-on-ubuntu-1804" rel="nofollow ugc">https://www.digitalocean.com/community/tutorials/how-to-set-up-ssh-keys-on-ubuntu-1804</a><br />
1.在客户端创建私钥和公钥</p>
<pre><code>$ ssh-keygen
</code></pre>
<p dir="auto">生成的私钥key默认保存在~/.ssh/id_rsa文件中。重复执行这个命令会覆盖这个文件，会导致之前的key无法使用。<br />
生成过程中会提示加密，建议输入一个密码进行安全保护。</p>
<pre><code>Output
Your identification has been saved in /your_home/.ssh/id_rsa.
Your public key has been saved in /your_home/.ssh/id_rsa.pub(公钥).
The key fingerprint is:
a9:49:2e:2a:5e:33:3e:a9:de:4e:77:11:58:b6:90:26 username@remote_host
The key's randomart image is:
+--[ RSA 2048]----+
|     ..o         |
|   E o= .        |
|    o. o         |
|        ..       |
|      ..S        |
|     o o.        |
|   =o.+.         |
|. =++..          |
|o=++.            |
+-----------------+
</code></pre>
<p dir="auto">2.将公钥上传到服务器<br />
方法一　使用ssh-copy-id　最简单</p>
<pre><code>$ ssh-copy-id username@remote_host
Output
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
username@203.0.113.1's password:
</code></pre>
<p dir="auto">方法二　拷贝</p>
<pre><code>cat ~/.ssh/id_rsa.pub | ssh username@remote_host "mkdir -p ~/.ssh &amp;&amp; touch ~/.ssh/authorized_keys &amp;&amp; chmod -R go= ~/.ssh &amp;&amp; cat &gt;&gt; ~/.ssh/authorized_keys"
</code></pre>
<p dir="auto">方法三　手动将id_rsq.pub的内容粘贴到服务器的~/.ssh/authorized_keys</p>
<pre><code>id_rsa.pub file to the ~/.ssh/authorized_keys
</code></pre>
<p dir="auto">3.登录远端服务器<br />
$ ssh username@remote_host</p>
<p dir="auto">4.禁用服务器的密码登录（可选）<br />
sudo nano /etc/ssh/sshd_config<br />
PasswordAuthentication no<br />
sudo systemctl restart ssh</p>
]]></description><link>http://an.forum.genostack.com/topic/3/ubuntu-18-04-ssh-key的配置以及免密登录</link><generator>RSS for Node</generator><lastBuildDate>Sat, 13 Jun 2026 12:30:16 GMT</lastBuildDate><atom:link href="http://an.forum.genostack.com/topic/3.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 18 Jul 2020 07:29:04 GMT</pubDate><ttl>60</ttl></channel></rss>