背景: 有时候我们在两个主机之间复制文件的时候,提示输入密码,很不方便,那如何免密码复制呢?,就是使用通过linux公钥和秘钥,建立双机信任关系。
1. 生成秘钥,并添加信任
我的环境中node1的ip是192.168.168.201,node2的ip是192.168.168.202.
[[email protected] ~]# ssh-keygen -t rsa -P ‘‘ -f ~/.ssh/id_rsa #生成rsa [[email protected] ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub [email protected]192.168.168.202 #复制公钥 [[email protected] ~]# ssh-keygen -t rsa -P ‘‘ -f ~/.ssh/id_rsa #生成rsa [[email protected] ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub [email protected]192.168.168.201 #复制公钥
2.测试
[[email protected] ~]# ssh 192.168.168.202 ‘ip addr show dev eth0 ‘ 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:50:56:3f:42:13 brd ff:ff:ff:ff:ff:ff inet 192.168.168.202/24 brd 192.168.168.255 scope global eth0 inet6 fe80::250:56ff:fe3f:4213/64 scope link valid_lft forever preferred_lft forever [[email protected] ~]# ssh 192.168.168.201 ‘ip addr show dev eth0‘ 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:c9:20:88 brd ff:ff:ff:ff:ff:ff inet 192.168.168.201/24 brd 192.168.168.255 scope global eth0 inet 192.168.168.200/24 brd 192.168.168.255 scope global secondary eth0 inet6 fe80::20c:29ff:fec9:2088/64 scope link valid_lft forever preferred_lft forever
时间: 2024-08-26 10:03:51