三步实现SSH无密码登录

  • ssh-keygen 产生公钥与私钥对
  • ssh-copy-id 将本机的公钥复制到远程机器的authorized_keys文件中

本地生成公私钥

$ ssh-keygen 
Generating public/private rsa key pair.
Enter file in which to save the key (/home/daodao/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/chengang/.ssh/id_rsa.
Your public key has been saved in /home/chengang/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:RymhT9wC+nuQHe9v6e9rSAUYQIxKuKbrEF1tAVWGiwY chengang@chengang-vm
The key's randomart image is:
+---[RSA 2048]----+
|   ..o+**..o     |
|  E .oo*.o...    |
|   +oo+.* +  .   |
| .o.+o.= *    .  |
|.o..  + S o  .   |
|..     o o  .    |
|..    . . .. o   |
|o      .   .+ .  |
|..         oo++. |
+----[SHA256]-----+

用ssh-copy-id将公钥复制到远程机器中

$ ssh-copy-id -i ~/.ssh/id_rsa.pub root@10.10.4.76
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/daodao/.ssh/id_rsa.pub"
The authenticity of host '10.10.4.76 (10.10.4.76)' can't be established.
RSA key fingerprint is SHA256:BERyt3qqK2giIkBJw0Nny1dEaKWdKxYGlF9rp6b9rT0.
Are you sure you want to continue connecting (yes/no)? yes
/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
root@10.10.4.76's password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'root@10.10.4.76'"
and check to make sure that only the key(s) you wanted were added.

登录到远程机器(不用输入密码)

$ ssh root@10.10.4.76
Last login: Fri Sep 30 2016 from 10.10.4.77
[root@localhost ~]# who
root     pts/0        2016-09-30 13:02 (10.10.4.77)
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容