我有两个带有ssh密钥的GitHub帐户设置,一个是个人的,另一个是企业。
我有这样一个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这两个密钥分别创建并附加到相应的帐户。
奇怪的是,我已经用了一个月了,而且起作用了。今天,当我登录时,我提交了一些关于我的个人回购的工作,当我试图做一个远程推送(以前是为这个回购工作),我得到和用户的许可被拒绝。
然后,我对两个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.个人密钥测试是错误的。它应该是Hi mervinhemaraju! You've successfully authenticated, but GitHub does not provide shell access.,因为mervinhemaraju是我的个人帐户,但它指的是企业帐户。
我在MacOs上。有人能帮忙吗?
发布于 2022-11-18 07:39:06
为ssh配置中的条目添加IdentitiesOnly yes。这将防止SSH代理尝试它知道的所有密钥,并且只使用配置文件中指定的键。
指定ssh只应使用ssh_config文件中配置的标识键,即使ssh代理提供更多标识。https://www.ssh.com/academy/ssh/config
发布于 2022-11-07 18:52:25
我也遇到过类似的问题,我所做的就是创建一个本地git配置,它显式地指定要使用哪个SSH键。
我的~/.ssh/config文件指定使用我的" work“ssh键,因为这在我的工作计算机上是最常见的。
我的~/.ssh/config里有这样的东西
Host *
PreferredAuthentications publickey
IdentityFile ~/.ssh/my-work-ssh-key
ServerAliveInterval 60在我的“个人”项目中,我将Git配置为忽略我的~/.ssh/config文件,并将标识文件设置为"personal“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/nullhttps://stackoverflow.com/questions/74351436
复制相似问题