准備:2台機器,ip分別為:192.168.0.195 192.168.1.210
目的:通過195ssh遠程訪問210.無需輸入密碼
1、首先在195上生成密鑰對。
#cd /root/.ssh
#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/id_rsa.pub.
The key fingerprint is:
06:96:6b:56:0c:33:a4:24:16:8c:06:35:9b:98:8b:e7 root@localhost.localdomain
2、在root/.ssh目錄下生成密鑰對 id_rsa和id_rsa.pub
其中id_rsa是私鑰,id_rsa.pub是公鑰。
3、將公鑰直接copy到210的/root/.ssh目錄下
#scp id_rsa.pub root@192.168.1.210:/root/.ssh
4、將210機器上的id_rsa.pub改名為authorized_keys
#cd /root/.ssh
#mv id_rsa.pub authorized_keys
5、密鑰設置成功。195ssh訪問210無需密碼成功
#ssh 192.168.1.210
成功啦