Centos7多台服务器免密登录

                Centos7多台服务器免密登录_第1张图片

准备四台服务器:

docker0

docker1

docker2

docker3

在docker0服务器上生成公钥和私钥

[root@www ~]# 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:
SHA256:QX9zBwLmVNRXXbgPLmPZr4515rXXe/GmmpYbc6k3tU8 [email protected]
The key's randomart image is:
+---[RSA 2048]----+
|        . +++...*|
|       . =   .o.o|
|        . o o .o.|
|         . . oo. |
|        S    + o |
|            = ooo|
|           .o++oE|
|            oOo*X|
|           .*=+BB|
+----[SHA256]-----+

Centos7多台服务器免密登录_第2张图片 

生成的公钥和私钥存储在/root/.ssh目录下面
[root@www ~]# cd /root/.ssh
[root@www .ssh]# ll
总用量 8
-rw-------. 1 root root 1679 8月  13 14:41 id_rsa
-rw-r--r--. 1 root root  403 8月  13 14:41 id_rsa.pub

验证下自己登录自己是否成功:

[root@www ~]# ssh-copy-id 192.168.1.100
Centos7多台服务器免密登录_第3张图片



(二) 节点docker0上的公钥与私钥拷贝到其他三台机器

scp -pr .ssh/ 192.168.1.101:root/

scp -pr .ssh/ 192.168.1.102:root/

scp -pr .ssh/ 192.168.1.103:root/

Centos7多台服务器免密登录_第4张图片

 (三)验证

[root@www ~]# ssh 192.168.1.101
Last login: Sun Aug 13 14:33:16 2023 from 192.168.1.5
[root@www ~]# ifconfig
ens32: flags=4163  mtu 1500
        inet 192.168.1.101  netmask 255.255.255.128  broadcast 192.168.1.127
        inet6 2409:8a00:79a4:9290:20c:29ff:feb7:c791  prefixlen 64  scopeid 0x0
        inet6 fe80::20c:29ff:feb7:c791  prefixlen 64  scopeid 0x20
        ether 00:0c:29:b7:c7:91  txqueuelen 1000  (Ethernet)
        RX packets 5059  bytes 391546 (382.3 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2130  bytes 223968 (218.7 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0


从docker1再次回到节点docker0

[root@www ~]# exit
登出
Connection to 192.168.1.101 closed.
[root@www ~]# ifconfig
ens32: flags=4163  mtu 1500
        inet 192.168.1.100  netmask 255.255.255.128  broadcast 192.168.1.127
        inet6 2409:8a00:79a4:9290:c586:1ca9:1eb9:7cd1  prefixlen 64  scopeid 0x0
        inet6 fe80::41b2:5b2a:c067:9234  prefixlen 64  scopeid 0x20
        ether 00:0c:29:df:cc:db  txqueuelen 1000  (Ethernet)
        RX packets 6262  bytes 500539 (488.8 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 3157  bytes 362677 (354.1 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 313  bytes 57926 (56.5 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 313  bytes 57926 (56.5 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
 

至此,多台服务器之间可以免密登录,相互拷贝

 

 

你可能感兴趣的:(服务器,运维)