多台Linux服务器之间互相免密登陆

环境:

三台Linux 服务器     

 IP                                          Release                         Hostname                                           

192.168.200.131              centos7                            ceph-node1

192.168.200.130              centos7                            ceph-node2

192.168.200.136              centos7                            ceph-node3

 

配置ceph-node1无密码连接ceph-node2和ceph-node3:

[root@ceph-node1 ~]# 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:FGrYUe6qiaKaRXz4sp/HLWJJvDeUsGaV+++EKe9fKwc root@ceph-node1

 

关于 ssh-keygen的参数解释:http://www.cnblogs.com/wangkongming/p/6362397.html

 

 [root@ceph-node1 ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.200.130
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@192.168.200.130's password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'root@192.168.200.130'"
and check to make sure that only the key(s) you wanted were added.

在客户端的/root目录下就是出现 .ssh文件夹,下面是对应的authorized_keys文件。

在ceph-node1上ssh到ceph-node2,这样就能实现无密码访问了。

 [root@ceph-node1 ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.200.136

这只是在ceph-node1上配置了对于ceph-node2和ceph-node3的无密码访问,接下来配置ceph-node2和ceph-node3对于其他服务器的无密码访问,只需要在对应的节点上做以上相同的操作即可。

原文地址:https://www.cnblogs.com/liuqiang0/p/8494126.html