環境:服務器
服務器A(172.16.1.2)dom
服務器B(172.16.1.3)ssh
在服務器Aide
1.執行生成祕鑰命令測試
[root@localhost ~]#ssh-keygen -t rsait
Generating public/private rsa key pair. #回車便可io
Enter file in which to save the key (/root/.ssh/id_rsa): ast
Enter passphrase (empty for no passphrase): class
Enter same passphrase again: file
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:
0f:79:e3:71:60:54:d7:1e:77:e7:36:97:9c:21:da:82 root@localhost
The key's randomart p_w_picpath is:
+--[ RSA 2048]----+
| ... .. |
| . o o=|
| + o ooO|
| E + . ==|
| S + o .o|
| = + |
| o |
| |
| |
+-----------------+
執行完後會在/root/.ssh/目錄下生成兩個文件
-rw------- 1 root root 1675 Dec 9 21:42 id_rsa
-rw-r--r-- 1 root root 391 Dec 9 21:42 id_rsa.pub
2.傳送祕鑰給服務器B
[root@localhost ~]#scp /root/.ssh/id_rsa.pub root@172.16.1.3:/root/.ssh/authorized_keys
root@172.16.1.3's password: #此次須要輸入密碼
3.測試
[root@localhost .ssh]# ssh root@172.16.1.3
Last login: Tue Dec 9 21:52:54 2014 from 172.16.1.3
[root@Good ~]# #此次不用輸入密碼了
若是服務器B也須要不用密碼ssh到服務器A的話,直接參考以上步驟便可
注:若是服務器A須要與多臺ssh信任,直接把其餘服務器上生成的祕鑰內容複製到服務器A上authorized_keys裏便可