【发布时间】:2022-01-15 17:40:55
【问题描述】:
我已经设置了 git config 如下:
Host ACCOUNT1
HostName github.com
Port 22
User git-username1
IdentityFile ~/.ssh/id_rsa_2
Host ACCOUNT2
HostName github.com
Port 22
User git-username2
IdentityFile ~/.ssh/id_rsa
当我 git push ACCOUNT1 staging 失败并显示“Permission denied...(PublicKey)”
这是因为无论我如何重新排列主机(上面的 ACCOUNTS1 和 ACCOUNTS2),Windows 总是使用IdentityFile ~/.ssh/id_rsa
直到我将IdentityFile ~/.ssh/id_rsa_2 重命名为IdentityFile ~/.ssh/id_rsa,然后git push ACCOUNT1 staging 工作......
所以每次我必须推送到一个帐户时,我都必须确保其私钥完全命名为“id_rsa”
有没有人有解决方案来确保 Windows 上的 git FOLLOW git config set IdentityFile 而不是完全落入“id_rsa”?
【问题讨论】:
-
您确实设置了配置的 ssh 部分,但您仍然需要配置 git 的远程配置以使用不同的 URL。请参阅
git push的手册页。 -
@A.H.我已将远程 url 设置为 git@gihtub.com:username/repo .... 这就是为什么当我更改密钥的命名以匹配 accounts1 和 accounts2 远程 URL 的 id_rsa 时它可以工作...