git 在 msysgit 窗口中永久添加 SSH 密钥

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7226860/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 05:55:07  来源:igfitidea点击:

Adding an SSH-key permanently in msysgit windows

gitsshgithubmsysgit

提问by Zasz

I am in a situation, where I need my msysgit to talk to github with different keys. However git bash insists on using the keyfile named id_rsa ONLY. If I do ssh -vT [email protected] I see only id_rsa being offered.

我处于一种情况,我需要我的 msysgit 使用不同的密钥与 github 交谈。但是 git bash 坚持使用名为 id_rsa ONLY的密钥文件。如果我执行 ssh -vT [email protected] 我只看到 id_rsa 被提供。

So whenever I need to use any other key I have to do all this,

因此,每当我需要使用任何其他键时,我都必须执行所有这些操作,

ssh-agent bash
ssh-add ~/.ssh/mygithubkey
git clone [email protected]:myaccount/myrepo.git

or rename mygithubkeyto id_rsawhenever i need it backing up the original id_rsa to another file anotherkey

或重命名mygithubkeyid_rsa每当我需要将原始 id_rsa 备份到另一个文件时anotherkey

and of course it is a pain, especially because the command history is also different across the regular git bash.

当然,这很痛苦,尤其是因为常规 git bash 的命令历史记录也不同。

Other answers in stackoverflow helped only to arrive at my above workaround. If I do

stackoverflow 中的其他答案仅有助于达到我的上述解决方法。如果我做

ssh-add ~/.ssh/mygithubkey

directly in my git bash, it says could not connect to ssh-agent. If I do

直接在我的 git bash 中,它说无法连接到 ssh-agent。如果我做

ssh-agent ssh-add ~/.ssh/mygithubkey
git pull
ssh -vT [email protected]

directly in my git bash, it says permission denied, it seems ssh-adddid not really add the key permanently! And the added key is not offered while looking at the debug messages in verbose mode.

直接在我的 git bash 中,它说权限被拒绝,似乎ssh-add并没有真正永久添加密钥!并且在详细模式下查看调试消息时不提供添加的密钥。

Is there anyway to permanently add a list of ssh keys to offer, when sshing into github? Im mostly a windows user today, so please be verbose in the answer.

无论如何,在 ssh 到 github 时,是否要永久添加要提供的 ssh 密钥列表?我今天主要是 Windows 用户,所以请在答案中详细说明。

回答by sschuberth

I'd suggest to use a ~/.ssh/configfile similar to this answer. Something like:

我建议使用~/.ssh/config类似于这个答案的文件。就像是:

Host github1
    User git
    Hostname github.com
    IdentityFile ~/.ssh/mygithubkey

Host github2
    User git
    Hostname github.com
    IdentityFile ~/.ssh/myothergithubkey

That way you could easily switch keys by typing either ssh github1or ssh github2to connect.

这样您就可以通过键入ssh github1ssh github2连接轻松切换键。