【问题标题】:MacOS Terminal: how to use a seccond ssh key?MacOS 终端:如何使用第二个 ssh 密钥?
【发布时间】:2013-06-13 02:44:54
【问题描述】:

我正在使用 MacOS 并希望使用第二个 ssh 密钥进行 SSH/Git 登录。
我在 ~/.ssh/ 中有两个密钥对

id_rsa
id_rsa.pub
id_rsa.gitlab
id_rsa.gitlab.pub

id_rsa 和 id_rsa.pub 是较旧的密钥。这把钥匙工作正常。但是在需要第二个密钥的地方,我无法登录。它尝试第一个键并失败。

运行此命令ssh-add /Users/kevin/.ssh/id_rsa.gitlab 会有所帮助。但是重新启动后,它不再工作了,我必须再次运行该命令。

每次重启后运行这个命令有没有更好的解决方案?

【问题讨论】:

    标签: macos git ssh terminal


    【解决方案1】:

    使用多个 ssh 密钥的方法是使用 ~/.ssh/config

    Host serverKey1
       Hostname server1 # or ip address of server1
       User serverUser
       IdentityFile ~/.ssh/id_rsa
    
    Host serverKey2
       Hostname server1 # or ip address of server1
       User serverUser
       IdentityFile ~/.ssh/id_rsa.gitlab 
    

    然后您需要为您的 ssh url 使用 scp 语法:

    git clone serverKey1:/my/repo
    git clone serverKey2:/my/repo
    

    serverKey1serverKey2 是您的 ~/.ssh/config 文件中的条目,以便将正确的服务器、用户和标识文件(公钥和私钥)传递给 ssh

    如果这些私钥受密码保护,you would still need to add them

    您可以在此 atlassian 帮助页面查看更多信息:“Configure multiple SSH identities for GitBash, Mac OSX, & Linux”。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-08-20
      • 2017-08-04
      • 2018-07-14
      • 2021-10-19
      • 2017-04-12
      • 2017-02-13
      • 2019-02-12
      • 2013-09-14
      相关资源
      最近更新 更多