【发布时间】:2022-01-20 06:31:41
【问题描述】:
我见过一些类似的问题(实际上我已经尝试过解决我见过的每一个问题),但没有人能解决这个问题。本质上,我想推送到两个不同的 Github 帐户,而不是每次都更改我的配置文件。
我正在尝试从同一个系统推送到两个不同的 Github 帐户,都使用 SSH。我正在通过 VSCode 使用 WSL。 ssh -T 适用于我的两个 RSA 文件,两个 Github 帐户都有相应的 SSH 密钥,当我的 .ssh/config 文件对每个文件都有特定设置时,我可以推送到每个帐户。
我的.ssh/config 文件如下所示:
# Personal Account
Host github.com-user1
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa
# Work Account
Host github.com-user2
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_user2
按原样,推送到帐户 user1 工作正常,但尝试推送到帐户 user2 会出错:
ERROR: Permission to user2/repo.git denied to user1.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
但是,如果我将第二节 (#Work Account) 的第一行更改为 Host github.com,我可以突然推送到帐户 user2!我只是...无法推送到 user1。我得到了上述错误的相反,现在Permission to user1/repo.git denied to user2.
我试过了:
将 both 设置为 Host github.com,但这会让我回到原来的问题(只能作为 user1 推送。)
它似乎只是在它看到的.ssh/config 文件中选择第一节(同时优先考虑Host github.com),但我需要它来响应我从哪个帐户推送。
git config user.name 和 user.email 被设置为每个 repo 的正确值。 User2 使用本地配置,而 User1 使用全局配置,但我认为这不是问题,因为我无需调整即可推送到两者。
我已将PreferredAuthentications publickey 和IdentitiesOnly yes 添加到这两个节中,并且我在其他人的此文件配置中看到了其他一些内容,但没有一个更改得到输出的错误。
Control Panel > Manage Windows Credentials 没有与之关联的 GitHub 凭据(我检查过,没有,没有任何内容被更改/删除)
【问题讨论】:
标签: github ssh ssh-config multiple-accounts