Centos7多台服务器免密登录

准备四台服务器:

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 root@www.yhchange.com

The key's randomart image is:

+---[RSA 2048]----+

| . +++...*|

| . = .o.o|

| . o o .o.|

| . . oo. |

| S + o |

| = ooo|

| .o++oE|

| oOo*X|

| .*=+BB|

+----[SHA256]-----+

生成的公钥和私钥存储在/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


(二) 节点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/

(三)验证

[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<UP,BROADCAST,RUNNING,MULTICAST> 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<global>

inet6 fe80::20c:29ff:feb7:c791 prefixlen 64 scopeid 0x20<link>

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<UP,LOOPBACK,RUNNING> mtu 65536

inet 127.0.0.1 netmask 255.0.0.0

inet6 ::1 prefixlen 128 scopeid 0x10<host>

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<UP,BROADCAST,RUNNING,MULTICAST> 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<global>

inet6 fe80::41b2:5b2a:c067:9234 prefixlen 64 scopeid 0x20<link>

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<UP,LOOPBACK,RUNNING> mtu 65536

inet 127.0.0.1 netmask 255.0.0.0

inet6 ::1 prefixlen 128 scopeid 0x10<host>

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

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

相关推荐
Zfox_15 分钟前
【Linux】进程信号全攻略(二)
linux·运维·c语言·c++
速盾cdn15 分钟前
速盾:vue的cdn是干嘛的?
服务器·前端·网络
安於宿命20 分钟前
【Linux】简易版shell
linux·运维·服务器
丶Darling.23 分钟前
MIT 6.S081 Lab1: Xv6 and Unix utilities翻译
服务器·unix·lab·mit 6.s081·英文翻译中文
追梦不止~27 分钟前
Docker常用命令+详解
运维·docker·容器
黑龙江亿林等保31 分钟前
深入探索哈尔滨二级等保下的负载均衡SLB及其核心算法
运维·算法·负载均衡
黄小耶@32 分钟前
linux常见命令
linux·运维·服务器
叫我龙翔33 分钟前
【计网】实现reactor反应堆模型 --- 框架搭建
linux·运维·网络
古驿幽情35 分钟前
CentOS AppStream 8 手动更新 yum源
linux·运维·centos·yum
BillKu36 分钟前
Linux(CentOS)安装 Nginx
linux·运维·nginx·centos