ssh遠程連接服務(二)三台虛擬機之間的免密登錄


創建三台虛擬機主機名分別為node01、node02、node03

在node01虛擬機上生成密鑰對

[root@node01 ~]# ssh-keygen 
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:
b5:64:87:c6:c3:cc:2b:3e:a8:60:4b:03:d1:5d:c9:48 root@node01.linux
.comThe key's randomart image is:
+--[ RSA 2048]----+
|   .Eo..         |
| . ...o  = .     |
|. . .     % .    |
| .       = =     |
|.       S o      |
| .     o .       |
|  =   . o        |
| o + .   .       |
|  . .            |
+-----------------+

然后將生成的公鑰分別復制到node02、node03的虛擬機上(前提三台虛擬機能互相ping通)

[root@node01 ~]# scp -r /root/.ssh/ root@192.168.22.130:/root/.ss
h/root@192.168.22.130's password: 
id_rsa                         100% 1679     1.6KB/s   00:00    
id_rsa.pub                     100%  403     0.4KB/s   00:00    
known_hosts                    100%  352     0.3KB/s   00:00    
authorized_keys                100%  403     0.4KB/s   00:00 
[root@node01 ~]# scp -r /root/.ssh/ root@192.168.22.100:/root/.ss
h/The authenticity of host '192.168.22.100 (192.168.22.100)' can't 
be established.ECDSA key fingerprint is a2:25:2d:c3:ef:90:24:5b:ab:e3:13:b6:0f:e
a:a0:de.Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.22.100' (ECDSA) to the list o
f known hosts.root@192.168.22.100's password: 
id_rsa                         100% 1679     1.6KB/s   00:00    
id_rsa.pub                     100%  403     0.4KB/s   00:00    
known_hosts                    100%  528     0.5KB/s   00:00    
authorized_keys                100%  403     0.4KB/s   00:00

查看node02、node03虛擬機上的/root/.ssh/目錄里是否有authorized_keys文件

[root@node02 ~]# ls /root/.ssh/
authorized_keys  id_rsa  id_rsa.pub  known_hosts

 

[root@node03 ~]# ls /root/.ssh/
authorized_keys  id_rsa  id_rsa.pub  known_hosts

 

驗證登錄

[root@node01 ~]# ssh root@192.168.22.130
Last failed login: Thu Jan  7 13:46:23 CST 2021 from 192.168.22.1
29 on ssh:nottyThere was 1 failed login attempt since the last successful login.
Last login: Thu Jan  7 13:44:40 2021 from 192.168.22.1
[root@node02 ~]# exit
登出
Connection to 192.168.22.130 closed.
[root@node01 ~]# ssh root@192.168.22.100
Last login: Thu Jan  7 00:35:18 2021 from 192.168.22.1
[root@node03 ~]#
[root@node02 ~]# ssh root@192.168.22.129
Last login: Thu Jan  7 13:38:41 2021 from 192.168.22.1
[root@node02 ~]# ssh root@192.168.22.100
Last login: Thu Jan  7 00:52:21 2021 from 192.168.22.129
[root@node03 ~]# ssh root@192.168.22.129
Last login: Thu Jan  7 13:52:40 2021 from 192.168.22.130
[root@node03 ~]# ssh root@192.168.22.130
Last login: Thu Jan  7 13:54:23 2021 from 192.168.22.129

這樣就完成了三台虛擬機之間的ssh免密登錄

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM