SSH案例:實現(xiàn)kafka01服務(wù)器能夠免密登錄kafka02和kafka03服務(wù)器的需求(不然后面一鍵啟動的腳本將無法使用)?
- 1:檢查每臺服務(wù)器是否都安裝了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服務(wù)器上執(zhí)行:(一直按回車即可?。?/strong>
[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服務(wù)器上執(zhí)行如下命令,將公鑰傳給kafka02服務(wù)器,實現(xiàn)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服務(wù)器是否可以免密登錄kafka02服務(wù)器:(測試成功了如下)
[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服務(wù)器上,把公鑰發(fā)給kafka03服務(wù)器(實現(xiàn)kafka01能夠免密登錄kafka02和kafka03服務(wù)器):
- 然后中途需要我們輸入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服務(wù)器是否可以免密登錄kafka03服務(wù)器:(測試成功了如下)
[root@kafka01 ~]# ssh kafka03
Last login: Wed Aug 31 13:14:03 2022 from kafka01
文章來源地址http://www.zghlxwxcb.cn/news/detail-719521.html
文章來源:http://www.zghlxwxcb.cn/news/detail-719521.html
到了這里,關(guān)于centos7系統(tǒng)下,實現(xiàn)1臺服務(wù)器免密登錄多臺服務(wù)器功能的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!