mac ssh免密登陆

作者: 火头陀 | 来源:发表于2018-12-27 11:50 被阅读3次

    问题

    使用ssh私钥登陆服务器或者使用github时经常提示

    Enter passphrase for key '/Users/xxx/.ssh/id_rsa':
    

    解决方案

    1. 执行
    ssh-add /Users/xxx/.ssh/id_rsa
    

    此方案只能临时生效,机器重启时需要重新执行此命令,原因是此命令只能将id_rsa加到当前session中,当ssh-agent重启时以前的记录会消失

    1. 执行
    ssh-add -K /Users/xxx/.ssh/id_rsa
    

    此命令能将私钥加入到钥匙串中,再通过设置钥匙串访问权限即可保证永久生效

    高版本mac OSX 系统执行 ssh-add -K .ssh/id_rsa,
    私钥成功添加到keychain,但是系统重启后仍然提示Enter file in which to save the key (/Users/test/.ssh/id_rsa)

    原因是高版本的mac OSX ssh默认不使用keychain

    解决方案如下

    在~/.ssh/config 添加如下配置

    Host *
    UseKeychain yes
    AddKeysToAgent yes
    IdentityFile ~/.ssh/id_rsa
    

    相关文章

      网友评论

        本文标题:mac ssh免密登陆

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