我有两个GitHub帐户设置ssh密钥,一个个人和一个企业。
我有一个ssh配置文件:
# * GitHub CKO SSH Key
Host github-enterprise
HostName github.com
AddKeysToAgent yes
UseKeychain yes
User git
IdentityFile ~/.ssh/id_ed25519_github
# * GitHub Personal SSH Key
Host github-personal
HostName github.com
AddKeysToAgent yes
UseKeychain yes
User git
IdentityFile ~/.ssh/gh_mervinhemaraju_ed25519
两个密钥分别创建并附加到各自的帐户。
奇怪的是,我已经用了一个月了,它还在工作。今天,当我登录时,我在我的个人repo上提交了一些工作,当我试图做一个远程推送(以前是为这个repo工作的)时,我得到了和用户权限被拒绝。
然后对两个ssh密钥执行ssh测试,结果如下:
ssh -T ssh -T git@github-personal
Hi mervin-hemaraju-enterprise! You've successfully authenticated, but GitHub does not provide shell access.
ssh -T git@github-enterprise
Hi mervin-hemaraju-cko! You've successfully authenticated, but GitHub does not provide shell access.
personal key test错误。应该是Hi mervinhemaraju! You've successfully authenticated, but GitHub does not provide shell access.
,因为mervinhemaraju是我的个人账号,但这里指的是企业账号。
我用的是MacOs。有人能帮帮忙吗?
为ssh配置项添加IdentitiesOnly yes
。这将防止SSH代理尝试它所知道的所有密钥,而只使用配置文件中指定的密钥。
指定ssh应该只使用ssh_config文件中配置的身份密钥,即使ssh-agent提供更多身份。https://www.ssh.com/academy/ssh/config
我有一个类似的问题,我所做的是创建一个本地git配置,明确指定使用哪个SSH密钥。
我的~/.ssh/config
文件指定使用我的"SSH密钥,因为这在我的工作电脑上是最常见的。
我在我的~/.ssh/config
中有这样的东西:
Host *
PreferredAuthentications publickey
IdentityFile ~/.ssh/my-work-ssh-key
ServerAliveInterval 60
在我的个人"我将Git配置为忽略我的~/.ssh/config
文件,并将身份文件设置为我的"个人"文件。SSH密钥。
像这样:
git config --local core.sshCommand "ssh -i ~/.ssh/my-personal-ssh-key -F /dev/null"
将以下内容放入.git/config
:
[core]
sshCommand = ssh -i ~/.ssh/my-personal-key -F /dev/null