本地创建公私钥,实现服务器免密登录

醉酒当歌 提交于 2020-01-21 22:01:58
  • 第一步
    ssh-keygen -t rsa -f ~/.ssh/id_rsa
    输入服务器登录密码
  • 第二步
    ssh-copy-id -i ~/.ssh/id_rsa.pub -p 8022 zhangsan@10.81.126.118
    此时使用 ssh luban@10.81.126.118 -p 8022 命令登录,会如下提示,要求输入私钥
    Enter passphrase for key ‘~/.ssh/id_rsa’:
  • 第三步
    将私钥添加到钥匙串中,按照提示输入私钥密码
    ssh-add -K ~/.ssh/id_rsa
  • 第四步
    新建config文件,配置config文件,实现免密快速登录
    vim ~/.ssh/config
    添加
    Host zs
    User zhangsna
    Hostname 10.81.126.118
    Port 8022
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/id_rsa
    UseKeychain yes
    AddKeysToAgent yes
  • 第五步
    ssh zs 直接登录服务器
    scp dir_local zs:dir_remote 跳过端口和密码
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!