god*_*yan 32 git ssh github ssh-keys
自从我把任何东西推到GitHub以来已经有一段时间了.我最初在计算机上设置了帐户,一切都很顺利.然后我将我的帐户更改为客户的帐户(因此我可以将代码推送到他们的私人存储库).
已经有一段时间了,现在我正在改回旧帐户,我遇到了麻烦.我生成了一个新的rsa_key,并且几乎遵循了这里的指令.
但是,当我输入:ssh -T git@github.com我得到:
嗨oldincorrectusername!您已成功通过身份验证,但GitHub不提供shell访问权限.
我也不能推送到我的回购,因为这个旧的客户端用户名未经授权.我在我的计算机和GitHub上的帐户设置上都仔细检查了我的ssh密钥.
我还设置了我的全局帐户变量:
git config --global user.name "Firstname Lastname"
git config --global user.email "your_email@youremail.com"
git config --global github.user username
git config --global github.token 0123456789yourf0123456789token
Run Code Online (Sandbox Code Playgroud)
它仍然是给我旧的用户名.
有什么建议?
谢谢,
Chr*_*sen 58
问题是你的本地ssh仍在向GitHub提供你的"旧"SSH密钥.当你在ssh-agent中加载一个GitHub识别的密钥(即你的"旧"密钥)但想要使用不同的GitHub识别密钥(即你的"新"密钥)时,通常会出现这种情况.
ssh按此顺序提供密钥:
由"指定键"我的意思是由指定的那些密钥-i的命令行选项或IdentityFile配置选项(其可以通过给予~/.ssh/config或-o命令行选项).
如果您的"旧"密钥已加载到代理中,但您的"新"密钥未加载,则ssh将始终在您的"新"密钥之前提供您的"旧"密钥(来自第一或第二类)(仅限于最后一个类别,因为它没有加载),即使你用-i/ 指定你的"新"键IdentitiesOnly.
您可以检查哪些键在被加载的ssh-agent用ssh-add -l.如果列出了您的"旧"密钥,那么您可以通过从代理中卸载来解决问题(确保还卸载任何其他GitHub识别的密钥,除了您的"新"密钥):
ssh-add -d ~/.ssh/old_key_file
Run Code Online (Sandbox Code Playgroud)
如果您使用的是Mac OS X,系统可能会自动加载您的"旧"密钥,如果您在一个位置提示输入密码时选中"记住我的钥匙串中的密码"; 您可以通过使用该命令删除密钥的Keychain条目来禁用此自动加载
/usr/bin/ssh-add -K -d ~/.ssh/old_key_file.其他系统可能会做类似的事情,但告诉他们"停止"的命令会有所不同.
您可以将IdentitiesOnly配置选项设置为yes,以告诉ssh跳过第二类键(未指定的代理加载键),而不是从代理中卸载"旧"键.你~/.ssh/config可能包括这样的部分:
Host github.com
User git
IdentityFile ~/.ssh/id_rsa # wherever your "new" key lives
IdentitiesOnly yes
Run Code Online (Sandbox Code Playgroud)
这样,将任何其他GitHub识别的密钥加载到您的代理中都无关紧要; ssh将始终只提供"新"密钥.
如果您预计需要访问两个GitHub帐户的存储库,并且您不希望在每次要在GitHub帐户之间切换时编辑配置文件,那么您可以设置~/.ssh/config如下:
Host clientname.github.com
HostName github.com
IdentityFile ~/.ssh/client_id_rsa # or wherever your "old" client key lives
Host github.com
IdentityFile ~/.ssh/id_rsa # or wherever your "new" key lives
Host github.com *.github.com
User git
Hostname github.com
IdentitiesOnly yes
Run Code Online (Sandbox Code Playgroud)
然后使用类似于github.com:GitHubAccount/repository您的存储库和URL的URL,例如clientname.github.com:GitHubAccount/repository您的客户端存储库(git@如果您愿意,可以将前缀放回原位,但由于上述条目设置了User配置变量,因此没有必要).
| 归档时间: |
|
| 查看次数: |
45342 次 |
| 最近记录: |