【问题标题】:why can't I interact with GitHub using SSH为什么我不能使用 SSH 与 GitHub 交互
【发布时间】:2021-10-09 18:19:57
【问题描述】:

当我尝试使用 ssh 从 GitHub 克隆我的项目时。

git clone git@github.com:{myname}/{myproject}.git

终端提示我输入

git@github.com's password:

在此之前,我已经生成了公钥,并放在了 GitHub 帐户中。

我的命令是

ssh-keygen -t rsa -C "$my_email"

而且我不知道为什么在使用 git clone 时要输入密码,我尝试了我的 Github 帐户和 Linux 帐户。但它没有用。我在这里错过了什么?


当运行ssh -Tv git@github.com 我得到了

OpenSSH_7.6p1 Ubuntu-4ubuntu0.3, OpenSSL 1.0.2n  7 Dec 2017
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to github.com [$my_linux_WAN_ip] port 22.
debug1: Connection established.
debug1: identity file /home/deeplearn/.ssh/id_rsa type 0
debug1: key_load_public: No such file or directory
debug1: identity file /home/deeplearn/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/deeplearn/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/deeplearn/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/deeplearn/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/deeplearn/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/deeplearn/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/deeplearn/.ssh/id_ed25519-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_7.6p1 Ubuntu-4ubuntu0.3
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.6p1 Ubuntu-4ubuntu0.3
debug1: match: OpenSSH_7.6p1 Ubuntu-4ubuntu0.3 pat OpenSSH* compat 0x04000000
debug1: Authenticating to github.com:22 as 'git'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:V2mCp8e57TQ9rLfhLv+ATIDG/l0c3z0Ynr2T/r7zdks
debug1: Host 'github.com' is known and matches the ECDSA host key.
debug1: Found key in /home/deeplearn/.ssh/known_hosts:1
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<ssh-ed25519,ssh-rsa,rsa-sha2-256,rsa-sha2-512,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Offering public key: RSA SHA256:EwlVGDfp7GYd+LT8l+dconPRVKhfwSbzkX2CRu+xIZA /home/deeplearn/.ssh/id_rsa
debug1: Authentications that can continue: publickey,password
debug1: Trying private key: /home/deeplearn/.ssh/id_dsa
debug1: Trying private key: /home/deeplearn/.ssh/id_ecdsa
debug1: Trying private key: /home/deeplearn/.ssh/id_ed25519
debug1: Next authentication method: password
git@github.com's password:

【问题讨论】:

  • ssh -Tv git@github.com 的输出是什么?请复制/粘贴文本并将其格式化为代码以使其可读。
  • 在尝试对 repo 使用 git 之前,您是否添加了私钥(使用 ssh-add)?欢迎来到 SO!
  • debug1: identity file /home/deeplearn/.ssh/id_rsa type 0 debug1: key_load_public: No such file or directory 表示您实际上并未将密钥存储在系统上。没关系如果您正在使用 ssh-agent 将密钥存储在其他地方并将其传递给需要它的程序...
  • "debug1: 可以继续的身份验证:publickey,password" Github 的 ssh 服务器不提供密码身份验证。远程软件版本对于 github 的服务器也是错误的。你实际上并没有与 github 通信。根据“连接到 github.com...”这一行,您实际上是在连接到您的本地系统之一...?

标签: git github ssh


【解决方案1】:

您的系统或网络配置有误。 github.com 的 IP 地址不应该是你的 Linux WAN 端口 IP,GitHub 不使用 OpenSSH 进行 SSH 访问,而且 GitHub 目前不提供 ECDSA 主机密钥,所以所有这些都表明你不是连接到您认为的服务器。

您的 /etc/hosts 文件可能包含 github.com 的条目,或者您的网络网关配置错误以拦截所有 SSH 流量。您应该对此进行更彻底的调查,然后验证主机密钥是否与 https://api.github.com/meta 的 RSA ssh_key_fingerprints 条目匹配。这是在连接之前验证 SSH 主机密钥很重要的原因之一。

【讨论】:

  • 非常感谢!我检查了我的/etc/hosts 并找到了 github.com 的错误条目 :)
  • 哈,我跳过了省略的 IP 地址文本。如果我注意到了,我会问他为什么把 $my_linux_WAN_ip 放在那里而不是 github 公共 IP...
猜你喜欢
  • 2017-11-27
  • 2020-08-21
  • 2019-06-20
  • 2012-02-09
  • 2022-11-02
  • 2020-12-13
  • 2020-11-15
  • 2012-10-30
  • 1970-01-01
相关资源
最近更新 更多