我有两把SSH钥匙。一个是我公司的github帐户,另一个是我的个人github帐户。在我为我的个人帐户创建另一个SSH密钥之前,我的公司帐户SSH密钥一直运行良好。我最后创建的SSH密钥对是为我的个人帐户创建的,它运行得很好。现在,我正试图推到我的公司帐户,但我收到一条错误信息。有什么方法可以同时使用SSH密钥或在它们之间切换吗?我将分享我的配置文件。第一个是我公司帐户的原始SSH密钥。
Host *
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/id_rsa
Host github.com
HostName github.com
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/id_ed25519
IdentitiesOnly yes发布于 2021-10-18 21:24:45
Git详细介绍了这个主题,包括为SSH和HTTPS。对于SSH,FAQ在您的~/.ssh/config中建议如下
# This is the account for author on git.example.org.
Host example_author
HostName git.example.org
User git
# This is the key pair registered for author with git.example.org.
IdentityFile ~/.ssh/id_author
IdentitiesOnly yes
# This is the account for committer on git.example.org.
Host example_committer
HostName git.example.org
User git
# This is the key pair registered for committer with git.example.org.
IdentityFile ~/.ssh/id_committer
IdentitiesOnly yes然后,它指出您需要更改您的URL:
然后,您可以调整您的推URL使用
git@example_author或git@example_committer而不是git@example.org(例如,git remote set-url git@example_author:org1/project1.git)。
显然,在您的示例中,您希望使用github.com代替git.example.org,并且可能希望对主机名使用不同的条目。
https://stackoverflow.com/questions/69622565
复制相似问题