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

问题描述 投票:7回答:1

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

因此,每当我需要使用任何其他密钥时,我必须完成所有这些,

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

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

当然这很痛苦,特别是因为命令历史在常规git bash中也有所不同。

stackoverflow中的其他答案只能帮助我解决上述问题。如果我做

ssh-add ~/.ssh/mygithubkey

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

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

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

无论如何,当sshing到github时,永久性地添加一个ssh密钥列表?我今天大多是Windows用户,所以请在答案中详细说明。

git ssh github msysgit
1个回答
6
投票

我建议使用类似于~/.ssh/configthis answer文件。就像是:

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

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

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

© www.soinside.com 2019 - 2024. All rights reserved.