Step1:在 Client 端建立 Public 与 Private Key

# ssh-keygen -t dsa <==这个步骤产生 Keys 
Generating public/private rsa key pair. 
Enter file in which to save the key (/root/.ssh/id_dsa): <== 按下 Enter 
Enter passphrase (empty for no passphrase): <== 按 Enter 
Enter same passphrase again: <== 再按一次 Enter 
Your identification has been saved in /root/.ssh/id_dsa. <== 私钥 
Your public key has been saved in /root/.ssh/id_dsa.pub. <== 公钥 
The key fingerprint is: 
c4:ae:d9:02:d1:ba:06:5d:07:e6:92:e6:6a:c8:14:ba test@test.com


Step2 : 在 Server 端放置 Client 可以登入的公钥

# ssh-copy-id -i ~/.ssh/id_rsa.pub 192.168.1.1
$The authenticity of host '192.168.1.1 (192.168.1.1)' can't be established.
RSA key fingerprint is f9:1c:f7:47:ca:d4:51:05:f3:1c:f1:88:a8:f2:e5:da.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.1.1' (RSA) to the list of known hosts.
root@192.168.1.1's password:     #此处需要输入远程主机的密码
Now try logging into the machine, with "ssh '192.168.1.1'", and check in:

  .ssh/authorized_keys

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


Step3 : 登入到 Server 端:

# ssh 192.168.1.1
可以免密码登陆到主机192.168.1.1


当首次远程登录的时候都得输入yes让.ssh/know_hosts记住主机.现在不用了,主要在$HOME/.ssh/config(没有文件就自己加上去)里加上一行即可:

$ vim $HOME/.ssh/config
StrictHostKeyChecking no