環境:
本地主機:ha01
eth0: 192.168.1.100 //對外IP地址
遠程主機:ha02
eth0: 192.168.1.200 //對外IP地址
本地主機ha01配置:
複製代碼 代碼如下:
[root@ha01 /]# cd /etc/ssh
[root@ha01 ssh]# ssh-keygen -t rsa -N "" (該步驟產生key公私金鑰組,-N ""表示金鑰組短語為空白)
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
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:
82:2c:74:43:8e:16:f4:ef:ac:91:0f:d7:6f:a6:f3:59 root@ha01
複製公用密鑰到遠程主機(原始方法):
若ha02伺服器上/root/.ssh/authorized_keys檔案不存在
複製代碼 代碼如下:
[root@ha01 ssh]# scp /root/.ssh/id_rsa.pub root@192.168.1.200:/root/.ssh/authorized_keys
若authorized_keys檔案存在
ha01上執行:
複製代碼 代碼如下:
[root@ha01 ssh]# scp /root/.ssh/id_rsa.pub root@192.168.1.200:/root/.ssh/
ha02上執行:
複製代碼 代碼如下:
[root@ha02 /]# cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys
複製公用密鑰到遠程主機(新方法):
可以使用ssh-copy-id方便安全的將公用密鑰複製到遠程主機
ha01上執行:
複製代碼 代碼如下:
[root@ha01 ssh]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.1.200
SSH登入測試:
複製代碼 代碼如下:
[root@ha01 ssh]# ssh ha02
Last login: Fri Apr 8 10:41:28 2011 from ha01