美文网首页
ssh-keygen和ssh-copy-id实现SSH无密钥登陆

ssh-keygen和ssh-copy-id实现SSH无密钥登陆

作者: 素白流殇 | 来源:发表于2016-11-16 23:45 被阅读806次

    生成公钥和私钥文件

    [root@localhost ~]# ssh-keygen -t rsa # -t选项指定需要加密的类型为rsa
    Generating public/private rsa key pair.
    Enter file in which to save the key (/root/.ssh/id_rsa): 
    /root/.ssh/id_rsa already exists.
    Overwrite (y/n)? y^H
    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:
    d5:5d:58:30:a7:45:a3:53:a8:ec:5d:89:19:7d:db:bb root@localhost.localdomain
    The key's randomart image is:
    +--[ RSA 2048]----+
    |              =B*|
    |           . ++Bo|
    |          o oo* =|
    |         . o o.+.|
    |        S . . . .|
    |           . . . |
    |                .|
    |               E |
    |                 |
    +-----------------+
    
    

    生成密钥对文件

    [root@localhost ~]# cd .ssh/
    [root@localhost .ssh]# ll
    total 12
    -rw------- 1 root root 1675 Nov 16 23:39 id_rsa
    -rw-r--r-- 1 root root  408 Nov 16 23:39 id_rsa.pub
    -rw-r--r-- 1 root root  396 Nov 16 23:31 known_hosts
    

    将公钥文件id_rsa.pub,copy到需要无密码登陆的服务器上

    [root@localhost ~]# ssh-copy-id -i id_rsa.pub remoteIP
    copy完成后会在远程服务器的.ssh/目录下生成authorized_key文件
    

    到此为止,已经实现了两台服务器之间互相信任,可以适用于rsync的自动备份环境中。

    相关文章

      网友评论

          本文标题:ssh-keygen和ssh-copy-id实现SSH无密钥登陆

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