【发布时间】:2021-04-26 04:46:32
【问题描述】:
Mac OS (High Sierra) 在这里。我有一个 SSH 密钥 example-gh-user,当我运行 pbcopy < ~/.ssh/example-gh-user.pub 并将其粘贴到编辑器中时,我看到了:
ssh-ed25519 <SOME_REALLY_LONG_ALPHANUM> me@example.org
显然出于安全原因,我将<SOME_REALLY_LONG_ALPHANUM> 和me@example.org 的实际 值替换为上面的虚拟值。但一切看起来都不错。
在 GitHub 上,我有一个用户 example-gh-user,正在使用 me@example.org 电子邮件,我可以使用该用户登录并查看我的所有存储库。一切看起来都很好。
我已关注GitHub guide on adding an SSH key 到我的example-gh-user GitHub 帐户。因此,此 SSH 密钥应与我的 GH 帐户所关联的同一电子邮件地址相关联。
在我的~/.ssh/config 文件中,我有以下条目:
Host example-dev
Hostname github2.com
AddKeysToAgent yes
IdentityFile ~/.ssh/example-gh-user
Host github.com
User git
Hostname github.com
AddKeysToAgent yes
PreferredAuthentications publickey
IdentityFile ~/.ssh/example-gh-user
到目前为止,我认为还不错。
但是,当我从命令行运行以下命令时:
ssh -Tv git@github.com
我得到了一个巨大的输出转储,有趣的是:
debug1: Sending environment.
debug1: Sending env LANG = en_US.UTF-8
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
Hi my-old-gh-user! You've successfully authenticated, but GitHub does not provide shell access.
debug1: channel 0: free: client-session, nchannels 1
Transferred: sent 3452, received 2724 bytes, in 0.1 seconds
Bytes per second: sent 28403.1, received 22413.1
debug1: Exit status 1
看那个! my-old-gh-user!那是我年没用过的老GH用户!
SSH 和/或 git/GitHub 从哪里获取 my-old-gh-user?! SSH 是否以某种方式缓存旧数据?如果我了解一切如何正常工作,~/.ssh/config 明确指示 SSH 在以git 用户身份连接到github.com 时使用~/.ssh/example-gh-user,对吗?我哪里出错了?
【问题讨论】:
-
感谢@JimB (+1) 的建议,我会试试的。听起来你想让我尝试从回购根目录运行
git config --global url.git@github.com:.insteadOf https://github.com/?只是好奇那会在引擎盖下做什么? -
您可以在链接的答案中看到它“在幕后”做了什么,它在 git 配置中添加了一个
insteadOf条目。insteadOf的完整描述可以在文档中找到,但基本上是;使用 ssh 而不是 https。 -
好的,我在 repo 的根目录中运行了
git config --global url.git@github.com:.insteadOf https://github.com/,然后尝试了go build,但得到了完全相同的错误。知道接下来我可以解决什么问题吗? -
它告诉我这与 Go 无关,你需要修复你的 git+ssh 配置。
标签: git macos github ssh ssh-config