1. Client端生成密钥:ssh-keygen -t rsa
2. 在Client端传送公钥到Server: ssh-copy-id -i user@remote_ip


[root@server1 ~]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/
The key fingerprint is:
The key's randomart image is:
+--[ RSA 2048]----+
|                 |
|                 |
|                 |
|                 |
|    o. +S        |
|   . +X.         |
|    +**+         |
|    oO*o         |
|    E+o+o        |

[root@server1 ~]# ssh-copy-id -i ~/.ssh/ root@
The authenticity of host ' (' can't be established.
RSA key fingerprint is 7e:3d:31:51:23:f0:08:d2:d6:a5:07:97:82:2e:84:fa.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '' (RSA) to the list of known hosts.
root@'s password: 
Now try logging into the machine, with "ssh 'root@'", and check in:


to make sure we haven't added extra keys that you weren't expecting.