centos7 ssh免密登录


配置多台centos 机器  免密登录: 
用于搭建集群,redis,storm...

现在有4台机器 主机名分别是 eshop-cache01 eshop-cache02 eshop-cache03 eshop-cache04

1、首先在eshop-cache02 ,eshop-cache03 eshop-cache04 三台机器上配置对本机的ssh免密码登录 (每台机器上都执行下面的命令) 生成本机的公钥,过程中不断敲回车即可,ssh-keygen命令默认会将公钥放在/root/.ssh目录下 ssh-keygen -t rsa 将公钥复制为authorized_keys文件,此时使用ssh连接本机就不需要输入密码了 cd /root/.ssh cp id_rsa.pub authorized_keys 2、把各个机器的公钥汇总到一台机器上(每台机器上都执行下面的命令) 先将每一台机器的公钥复制到其中某一台机器中,即让某一台机器可以访问所有机器。 使用ssh-copy-id -i hostname命令将本机的公钥拷贝到指定机器的 authorized_keys 文件中,每台机器上都执行这个命令。 比如: 将所有的公钥都集中到 eshop-cache01 这台机器上。 在02 03 04 上敲命令: ssh-copy-id -i eshop-cache01 3、将这 01 台机器的 authorized_keys 文件复制到其他所有机器 scp /root/.ssh/authorized_keys eshop-cache02:/root/.ssh
02,03 也是一样的操作.... 复制完后,再用ssh每台机器都相互登录一下,主要是为了敲一下这个 yes。 The authenticity of host 'eshop-cache02 (192.168.1.162)' can't be established. RSA key fingerprint is 11:02:69:08:e2:10:b2:e2:db:c5:34:d4:4d:18:a7:4a. Are you sure you want to continue connecting (yes/no)? yes 测试命令为: 在02 03 04 上 敲 : ssh eshop-cache01

退出 eshop=cache01: exit

 

posted @ 2020-03-12 15:16  shijiu520  阅读(233)  评论(0)    收藏  举报