SSH案例:实现kafka01服务器能够免密登录kafka02和kafka03服务器的需求(不然后面一键启动的脚本将无法使用)⭐
- 1:检查每台服务器是否都安装了SSH:
[root@kafka01 ~]# rpm -qa |grep ssh
openssh-clients-7.4p1-21.el7.x86_64
libssh2-1.8.0-4.el7.x86_64
openssh-7.4p1-21.el7.x86_64
openssh-server-7.4p1-21.el7.x86_64
- 2:在kafka01服务器上执行:(一直按回车即可!)
[root@kafka01 ~]# cd /root
[root@kafka01 ~]# ssh-keygen
-
3:查看kafka01的.ssh目录:
- id_rsa (私钥)
- id_rsa.pub (公钥)
[root@kafka01 ~]# cd /root/.ssh && ls
id_rsa id_rsa.pub
-
4:在kafka01服务器上执行如下命令,将公钥传给kafka02服务器,实现kafka01能够免密登录kafka02:
- 然后中途需要我们输入kafka02的密码,再按回车即可!
[root@kafka01 .ssh]# ssh-copy-id -i ~/.ssh/id_rsa.pub kafka02
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host 'kafka02 (192.168.184.202)' can't be established.
ECDSA key fingerprint is SHA256:VgM185hBJVyOYeb0tUEXlfALadKx63UcN0OeWAWf1CI.
ECDSA key fingerprint is MD5:6e:8a:c1:a5:c7:9a:a0:a9:47:bc:ad:76:1b:93:c7:5f.
Are you sure you want to continue connecting (yes/no)? yes
/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@kafka02's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'kafka02'"
and check to make sure that only the key(s) you wanted were added.
- 5:测试kafka01服务器是否可以免密登录kafka02服务器:(测试成功了如下)
[root@kafka01 ~]# ssh kafka02
Last failed login: Wed Aug 31 12:43:58 CST 2022 from kafka01 on ssh:notty
There were 5 failed login attempts since the last successful login.
Last login: Wed Aug 31 10:56:46 2022 from 192.168.184.1
-
6:在kafka01服务器上,把公钥发给kafka03服务器(实现kafka01能够免密登录kafka02和kafka03服务器):
- 然后中途需要我们输入kafka03的密码,再按回车即可!
[root@kafka01 ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub kafka03
/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@kafka03's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'kafka03'"
and check to make sure that only the key(s) you wanted were added.
- 7:测试kafka01服务器是否可以免密登录kafka03服务器:(测试成功了如下)
[root@kafka01 ~]# ssh kafka03
Last login: Wed Aug 31 13:14:03 2022 from kafka01
文章来源地址https://www.toymoban.com/news/detail-719521.html
文章来源:https://www.toymoban.com/news/detail-719521.html
到了这里,关于centos7系统下,实现1台服务器免密登录多台服务器功能的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!