######建立兩臺主機之間的ssh信任通道

setup1:準備環境
在ns1.benet.com上:

[root@ns1 ~]# hostname ns1.benet.com
[root@ns1 ~]# vi /etc/hosts
192.168.4.11    ns1.benet.com   ns1
192.168.4.22    ns2.benet.com   ns2


在ns2.benet.com上:

[root@ns2 ~]# hostname ns2.benet.com
[root@ns2 ~]# vi /etc/hosts
192.168.4.11    ns1.benet.com   ns1
192.168.4.22    ns2.benet.com   ns2

=================================================================================
setup2:創建密鑰對

在ns1.benet.com上:
[root@ns1 ~]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
Created directory '/root/.ssh'.
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:
80:21:85:60:ed:76:8c:d8:b3:4f:a8:6e:ae:fb:b5:65 [email protected]
[root@ns1 ~]# ls .ssh/
id_rsa  id_rsa.pub

在ns2.benet.com上:
[root@ns2 ~]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
Created directory '/root/.ssh'.
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:
3a:d0:27:fd:3c:55:74:15:29:fe:c8:9f:4b:87:c5:96 [email protected]
[root@ns2 ~]# ls .ssh/
id_rsa  id_rsa.pub

=================================================================================
setup3:建立通信信任

在ns1.benet.com上:
[root@ns1 ~]# cat ~root/.ssh/id_rsa.pub > ~root/.ssh/authorized_keys
[root@ns1 ~]# ssh [email protected] cat ~root/.ssh/id_rsa.pub >> ~root/.ssh/authorized_keys
The authenticity of host 'ns2.benet.com (192.168.4.22)' can't be established.
RSA key fingerprint is 6e:9d:7a:2d:98:87:46:f1:48:47:f4:04:62:b6:29:4b.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'ns2.benet.com,192.168.4.22' (RSA) to the list of known hosts.
[email protected]'s password: 
[root@ns1 ~]# scp ~root/.ssh/authorized_keys [email protected]:~root/.ssh
[email protected]'s password: 
authorized_keys                                         100%  800     0.8KB/s   00:00

=================================================================================
setup4:驗證通信通道是否打通

在ns1.benet.com上:
[root@ns1 ~]# ssh [email protected] hostname
ns2.benet.com

在ns2.benet.com上:
[root@ns2 ~]# ssh [email protected] hostname
ns1.benet.com

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章