问题描述
自从我将任何东西推送到GitHub以来已经有一段时间了。我最初在我的电脑上设置了我的帐户,一切都很顺利。然后我将帐户更改为客户的帐户(这样我就可以将代码推送到他们的私人存储库)。
这已经有一段时间了,现在我正在更换回我的旧帐户,我有麻烦。我生成了一个新的rsa_key,并且几乎遵循到T.
然而,当我输入: ssh -T [email protected]
我得到:
您好oldincorrectusername!您已成功通过身份验证,但GitHub不提供shell访问。
我无法推送到我的回购站,因为这个旧客户端用户名未经授权。我已经在我的计算机和GitHub上的帐户设置中加倍检查了我的ssh密钥。
我还设置了全局帐户变量:
git config --global user.name名字姓氏
git config --global [email protected]
git config --global github.user username $ b $ git config --global github.token 0123456789yourf0123456789token
仍然给我旧用户名。
有什么建议?
谢谢,
问题是您的本地 ssh 仍然将您的旧SSH密钥提供给GitHub。当你在一个 ssh-agent 中加载一个GitHub认可的密钥(即你的旧密钥),但想使用不同的GitHub认可密钥(即你的新密钥)。
ssh 提供按键顺序:
- 已加载到代理中的指定密钥 已加载到代理中的其他密钥
-
- 尚未加载的指定密钥进入代理
指定键指的是由 -i
命令行选项或 IdentityFile
配置选项(可通过〜/ .ssh / config
或 -o
命令行选项)。
如果您的旧密钥已加载到代理中,但您的new键不是,那么在你的新键之前, ssh 将始终提供你的旧键(来自第一或第二类)即使你使用 -i
/ IdentitiesOnly
。
您可以使用 ssh来检查您的 ssh-agent -add -l 。如果您的旧密钥已列出,那么您可以通过从代理中卸载该问题来解决该问题(确保还要卸载任何其他GitHub认可的密钥,除了可能是您的新密钥):
ssh-add -d〜/ .ssh / old_key_file
如果您使用的是Mac OS X,系统可能会自动加载您的旧密钥,如果您在提示输入密码时选中了记住我的密钥链中的密码;您可以使用命令
/ usr / bin / ssh-add -K -d〜/ .ssh / old_key_file 删除钥匙的钥匙串入口, code>。其他系统可能会做类似的事情,但告诉他们停止的命令将有所不同。
卸载代理中的旧密钥,您可以将 IdentitiesOnly
配置选项设置为 yes
,以告诉 ssh 跳过第二类密钥(非指定的代理加载密钥)。您的〜/ .ssh / config
可能包含这样的部分:
主机github.com
用户git
IdentityFile〜/ .ssh / id_rsa#无论您的新密钥在哪里生存
IdentitiesOnly是
这样,GitHub认可的其他密钥是否加载到您的代理中并不重要;如果您预计需要访问两个GitHub帐户的存储库,并且您不希望其他用户访问这些存储库,那么总是仅提供您的新密钥。 当你想要在GitHub帐户之间切换时必须编辑配置文件,那么你可以像下面这样设置你的〜/ .ssh / config
:
主机clientname.github.com
HostName github.com
IdentityFile〜/ .ssh / client_id_rsa#或无论您的旧客户端密钥生命
主机github.com
IdentityFile〜/ .ssh / id_rsa#或无论您的新密钥存活在哪里
主机github.com * .github。 com
User git
Hostname github.com
IdentitiesOnly yes
然后使用像 github.com:GitHubAccount/repository
这样的URL来存储您的存储库和URL,例如 clientname.github.com:GitHubAccount/repository
为你的客户的仓库(你可以把 git @ $如果你愿意的话,c $ c>可以加上前缀,但由于上面的条目设置了
User
配置变量,所以它不是必须的。)
It's been a while since I pushed anything to GitHub. I had initially set up my account on my computer, and everything worked great. Then I changed my account to a client's account (so I could push code to their private repository).
It's been a while and now I am changing back to my old account, and I am having trouble. I generated a new rsa_key and pretty much followed the instructions here to a T.
However, when I type: ssh -T [email protected]
I get:
Hi oldincorrectusername! You've successfully authenticated, but GitHub does not provide shell access.
I can't push to my repos either, because this old client username isn't authorized. I've doublechecked my ssh keys both on my computer and on my account setting on GitHub.
I've also set my global account variables:
git config --global user.name "Firstname Lastname"
git config --global user.email "[email protected]"
git config --global github.user username
git config --global github.token 0123456789yourf0123456789token
And still it is giving me the old username.
Any suggestions?
Thanks,
The problem is that your local ssh is still offering your "old" SSH key to GitHub. This often comes up when you have one GitHub-recognized key (i.e. your "old" key) loaded in an ssh-agent but want to use a different GitHub-recognized key (i.e. your "new" key).
ssh offers keys in this order:
- specified keys that have been loaded into the agent
- other keys that have been loaded into the agent
- specified keys that have not been loaded into the agent
By "specified keys" I mean those keys specified by the -i
command line option or the IdentityFile
configuration option (which can be given through ~/.ssh/config
or the -o
command line option).
If your "old" key is loaded into the agent, but your "new" key is not, then ssh will always offer your "old" key (from the first or second categories) before your "new" key (only ever in the last category since it is not loaded), even when you specify your "new" key with -i
/IdentitiesOnly
.
You can check which keys are loaded in your ssh-agent with ssh-add -l
. If your "old" key is listed, then you can fix the problem by unloading it from your agent (be sure to also unload any other GitHub-recognized keys, except perhaps your "new" key):
ssh-add -d ~/.ssh/old_key_file
If you are using Mac OS X, the system may be automatically loading your "old" key if you checked "Remember password in my keychain" when prompted for the password at one point; you can disable this automatic loading by deleting the Keychain entry for the key with the command/usr/bin/ssh-add -K -d ~/.ssh/old_key_file
. Other systems may do something similar, but the commands to tell them to "stop that" will be different.
Instead of unloading the "old" key from your agent, you can set the IdentitiesOnly
configuration option to yes
, to tell ssh to skip the second category of keys (non-specified agent-loaded keys). Your ~/.ssh/config
might include a section like this:
Host github.com
User git
IdentityFile ~/.ssh/id_rsa # wherever your "new" key lives
IdentitiesOnly yes
This way, it will not matter whether any other GitHub-recognized keys are loaded into your agent; ssh will always offer only your "new" key.
If you anticipate needing to access the repositories of both GitHub accounts and you do not want to have to edit the configuration file whenever you want to switch between GitHub accounts, then you might setup your ~/.ssh/config
like this:
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
Then use URLs like github.com:GitHubAccount/repository
for your repositories and URLs like clientname.github.com:GitHubAccount/repository
for your client’s repositories (you can put the git@
prefix back in if you like, but it is not necessary since the above entries set the User
configuration variable).
这篇关于无法在终端上切换Github帐户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!