• centos7系统下,实现1台服务器免密登录多台服务器功能


    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
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 2:在kafka01服务器上执行:(一直按回车即可!)
    [root@kafka01 ~]# cd /root
    
    • 1
    [root@kafka01 ~]# ssh-keygen
    
    • 1
    • 3:查看kafka01的.ssh目录:
      • id_rsa (私钥)
      • id_rsa.pub (公钥)
    [root@kafka01 ~]# cd /root/.ssh && ls 
    id_rsa  id_rsa.pub
    
    • 1
    • 2
    • 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.
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 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
    
    • 1
    • 2
    • 3
    • 4
    • 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.
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 7:测试kafka01服务器是否可以免密登录kafka03服务器:(测试成功了如下)
    [root@kafka01 ~]# ssh kafka03
    Last login: Wed Aug 31 13:14:03 2022 from kafka01
    
    • 1
    • 2
  • 相关阅读:
    vue之sourcemap
    来了,永久免费的图床服务
    Boost ASIO: Coroutines
    网安学习笔记-day14,nmap和hydra常用命令
    【毕业设计】基于单片机的智慧农业管理系统 -大棚管理系统 自动灌溉系统
    JUC并发编程第八篇,谈谈你对CAS的理解?自旋锁,CAS底层原理和存在的问题?
    无重复字符的最长子串
    【POJ No. 3253】 围栏修复 Fence Repair
    【实践篇】基于CAS的单点登录实践之路
    systemverilog学习 --- 数组操作(二)
  • 原文地址:https://blog.csdn.net/weixin_50071998/article/details/126622010