美文网首页
linux免密码登陆

linux免密码登陆

作者: 姚晨晨 | 来源:发表于2018-06-03 22:31 被阅读0次
    1. 生成密钥
     ➜  .ssh ssh-keygen -t rsa
    Generating public/private rsa key pair.
    Enter file in which to save the key (~/.ssh/id_rsa):
    Enter passphrase (empty for no passphrase):
    Enter same passphrase again:
    Your identification has been saved in ~/.ssh/id_rsa.
    Your public key has been saved in ~/.ssh/id_rsa.pub.
    The key fingerprint is:
    SHA256:ExgdQNetjvhIt7B9BXQ3tCOTSpq5HP+s3UZlQS42bKg xxxx@xxxdeMacBook-Pro.local
    The key's randomart image is:
    +---[RSA 2048]----+
    |     .+ooo . .o. |
    |       +. o =.+o |
    |      . ...++Boo.|
    |         *+.ooo.o|
    |       .SE..   o |
    |      +.o=. . .  |
    |     . Bo... .   |
    |      o + .+ ..  |
    |         ...+..  |
    +----[SHA256]-----+
    
    1. 公钥上传到服务器
    scp -P 22000 ~/.ssh/id_rsa.pub username@192.168.0.141:~/.ssh/temp001
    

    登录服务器,公钥保存为authorized_keys

    cat ~/.ssh/temp001 >> ~/.ssh/authorized_keys
    rm ~/.ssh/temp001
    
    1. 配置本地ssh config文件
    ➜  .ssh touch config
    

    config文件内容如下

    Host hdhost
      HostName 192.168.0.141
      Port 22000
      User root
      IdentityFile ~/.ssh/id_rsa
    
    1. 免密码登录
    ➜  .ssh ssh hdhost
    Last login: Sun Jun  3 22:34:40 2018 from 192.168.0.141
    Welcome to Alibaba Cloud Elastic Compute Service !
    [root@izuf61kij6ti02tzbzl3pqz ~]#
    

    相关文章

      网友评论

          本文标题:linux免密码登陆

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