三步实现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 [email protected]
/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
[email protected]'s password: 

Number of key(s) added: 1

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

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

$ ssh [email protected]
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)

你可能感兴趣的:(三步实现SSH无密码登录)