Linux免密登陆

作者: 夹胡碰 | 来源:发表于2020-08-04 14:35 被阅读0次

    参考

    Linux机器之间免密登录设置

    1. 配置两台Linux服务器,均为Centos7

    master: 192.168.1.89
    node: 192.168.1.65

    2. master生成ssh密钥

    ssh-keygen -t rsa

    一路回车

    [root@bogon .ssh]# ssh-keygen -t rsa
    Generating public/private rsa key pair.
    Enter file in which to save the key (/root/.ssh/id_rsa): 
    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:U+He9vxeISDtG2nT5EZULBNrQAJtn4b2HUcFX3Gi7bg root@bogon
    The key's randomart image is:
    +---[RSA 2048]----+
    |       .o.oo o*+*|
    |         +o.o=.=o|
    |        ..=oo== .|
    |         =o=O+ . |
    |        S +*==+. |
    |         ..o==. .|
    |           .E o .|
    |               ..|
    |               .o|
    +----[SHA256]-----+
    

    3. 查看master生成的公钥私钥

    在~/.ssh文件夹下,有id_rsa、id_rsa.pub两个文件

    * id_rsa : 生成的私钥文件 *
    * id_rsa.pub : 生成的公钥文件*
    

    4. 复制公钥文件到node服务器上并重命名为authorized_keys

    在master上使用 ssh-copy-id 命令

    ssh-copy-id -i ~/.ssh/id_rsa.pub 192.168.1.65

    5. master首次远程node

    [root@bogon .ssh]# ssh 192.168.1.65
    The authenticity of host '192.168.1.65 (192.168.1.65)' can't be established.
    ECDSA key fingerprint is SHA256:JHXcH2MD3f7NaTDe0FGeC8liVsJwD+LuOSWgjXI9Pzo.
    ECDSA key fingerprint is MD5:48:55:78:07:c9:d2:0b:5b:74:cc:e1:71:6e:5e:eb:f1.
    Are you sure you want to continue connecting (yes/no)? yes
    Warning: Permanently added '192.168.1.65' (ECDSA) to the list of known hosts.
    Last login: Tue Aug  4 14:22:50 2020 from 192.168.1.89
    

    6. master再次远程node的时候可直接登录

    [root@bogon .ssh]# ssh 192.168.1.65
    Last login: Tue Aug  4 14:32:40 2020 from 192.168.1.89
    

    相关文章

      网友评论

        本文标题:Linux免密登陆

        本文链接:https://www.haomeiwen.com/subject/xxkwrktx.html