【发布时间】:2021-03-10 01:03:36
【问题描述】:
我已经设置了我的~/.ssh/config 文件,允许我在两个不同的帐户上使用 ssh 连接到 GitHub:
Host *
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/id_rsa
Host alt
AddKeysToAgent yes
HostName github.com
IdentityFile ~/.ssh/id_ed25519
我将~/.ssh/id_rsa 密钥用于我的第一个 GitHub 帐户(id_rsa.pub 粘贴在 GitHub 设置中)。
我今天为我的 discord alt 生成了一个新密钥,并将 id_ed25519.pub 粘贴到我的 alt 的 GitHub 设置中。
现在当我执行ssh git@github.com 时,我得到(如预期的那样)
PTY allocation request failed on channel 0
Hi original_account! You've successfully authenticated, but GitHub does not provide shell access.
Connection to github.com closed.
但我似乎无法用新帐户进行身份验证,看看这个
现在当我执行ssh git@github.com 时,我得到了(如预期的那样)
$ ssh git@alt
PTY allocation request failed on channel 0
Hi original_account! You've successfully authenticated, but GitHub does not provide shell access.
Connection to github.com closed.
为什么它仍然认为我是original_account?甚至
$ ssh -o "IdentitiesOnly=yes" -i ~/.ssh/id_ed25519 git@alt
PTY allocation request failed on channel 0
Hi original_account! You've successfully authenticated, but GitHub does not provide shell access.
Connection to github.com closed.
如何强制 git 识别我希望使用的两个私钥之间的区别,以便我可以在同一台笔记本电脑上通过 ssh 使用这两个帐户?
ssh -vvv -o "IdentitiesOnly=yes" -i ~/.ssh/id_ed25519 git@alt
显示一些线条
debug1: Connecting to github.com port 22.
debug1: Connection established.
debug1: identity file /Users/theonlygusti/.ssh/id_ed25519 type 3
debug1: identity file /Users/theonlygusti/.ssh/id_ed25519-cert type -1
debug1: identity file /Users/theonlygusti/.ssh/id_rsa type 0
debug1: identity file /Users/theonlygusti/.ssh/id_rsa-cert type -1
debug1: identity file /Users/theonlygusti/.ssh/id_ed25519 type 3
debug1: identity file /Users/theonlygusti/.ssh/id_ed25519-cert type -1
...
debug1: Will attempt key: /Users/theonlygusti/.ssh/id_rsa RSA SHA256:avZRhZ1AbwN1ECfb1A/93OG8dm0ewx33pD6asJs/I2Y explicit agent
debug1: Will attempt key: /Users/theonlygusti/.ssh/id_ed25519 ED25519 SHA256:XWhJ7Gkt13Rh3Whqwf9yH/K4lL15HaoX1+cYvbxgfpY explicit agent
debug1: Will attempt key: /Users/theonlygusti/.ssh/id_ed25519 ED25519 SHA256:XWhJ7Gkt13Rh3Whqwf9yH/K4lL15HaoX1+cYvbxgfpY explicit
【问题讨论】:
-
检查
ssh -vvv的输出,看看实际使用的是哪个键。 -
@iBug 我用我认为相关的行编辑了这个问题