【问题标题】:Configue SSH to connect to GitHub failed配置 SSH 连接到 GitHub 失败
【发布时间】:2022-09-30 20:30:16
【问题描述】:

我生成了一对 rsa 密钥,然后我把公钥放在 github 上, 但是当我尝试ssh git@github.com时,它仍然需要一个密码,就像这样:

$ ssh git@github.com
git@github.com\'s password:

我确定我已经通过ssh-keygen -t rsa -C \"xxx\" 创建了正确的私钥和公钥

uchin@DESKTOP-UCHIN MINGW64 ~/.ssh
$ ls -lah
total 74K
drwxr-xr-x 1 uchin 197121    0 Sep 30 19:46 ./
drwxr-xr-x 1 uchin 197121    0 Sep 30 19:25 ../
-rw-r--r-- 1 uchin 197121  576 Sep 30 19:45 id_rsa.pub
-rw-r--r-- 1 uchin 197121 2.6K Sep 30 19:45 id_rsa.rsa
-rw-r--r-- 1 uchin 197121  484 Sep 30 19:46 known_hosts

我也上传了我的公钥,github public key

我已经尝试了很多次,但它从来没有奏效。

这是ssh -Tv git@github.com的一些信息

$ ssh -Tv git@github.com
OpenSSH_9.0p1, OpenSSL 1.1.1q  5 Jul 2022
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to github.com [::1] port 22.
debug1: connect to address ::1 port 22: Connection refused
debug1: Connecting to github.com [223.75.236.241] port 22.
debug1: Connection established.
debug1: identity file /c/Users/uchin/.ssh/id_rsa type 0
debug1: identity file /c/Users/uchin/.ssh/id_rsa-cert type -1
debug1: identity file /c/Users/uchin/.ssh/id_ecdsa type -1
debug1: identity file /c/Users/uchin/.ssh/id_ecdsa-cert type -1
debug1: identity file /c/Users/uchin/.ssh/id_ecdsa_sk type -1
debug1: identity file /c/Users/uchin/.ssh/id_ecdsa_sk-cert type -1
debug1: identity file /c/Users/uchin/.ssh/id_ed25519 type -1
debug1: identity file /c/Users/uchin/.ssh/id_ed25519-cert type -1
debug1: identity file /c/Users/uchin/.ssh/id_ed25519_sk type -1
debug1: identity file /c/Users/uchin/.ssh/id_ed25519_sk-cert type -1
debug1: identity file /c/Users/uchin/.ssh/id_xmss type -1
debug1: identity file /c/Users/uchin/.ssh/id_xmss-cert type -1
debug1: identity file /c/Users/uchin/.ssh/id_dsa type -1
debug1: identity file /c/Users/uchin/.ssh/id_dsa-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_9.0
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.6
debug1: compat_banner: match: OpenSSH_7.6 pat OpenSSH_7.0*,OpenSSH_7.1*,OpenSSH_7.2*,OpenSSH_7.3*,OpenSSH_7.5*,OpenSSH_7.6*,OpenSSH_7.7* compat 0x04000002
debug1: Authenticating to github.com:22 as \'git\'
debug1: load_hostkeys: fopen /c/Users/uchin/.ssh/known_hosts2: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: rsa-sha2-512
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: SSH2_MSG_KEX_ECDH_REPLY received
debug1: Server host key: ssh-rsa SHA256:rEmlJenVMSL5GVemSY0Gk8WGw6B4ege4J85M+vup8R0
debug1: load_hostkeys: fopen /c/Users/uchin/.ssh/known_hosts2: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory
debug1: Host \'github.com\' is known and matches the RSA host key.
debug1: Found key in /c/Users/uchin/.ssh/known_hosts:2
debug1: rekey out after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey in after 134217728 blocks
debug1: Will attempt key: /c/Users/uchin/.ssh/id_rsa RSA SHA256:ryU3w/a2yayTwFk3eNMI7NoyEugbQgYMrulXT9f/oeY
debug1: Will attempt key: /c/Users/uchin/.ssh/id_ecdsa
debug1: Will attempt key: /c/Users/uchin/.ssh/id_ecdsa_sk
debug1: Will attempt key: /c/Users/uchin/.ssh/id_ed25519
debug1: Will attempt key: /c/Users/uchin/.ssh/id_ed25519_sk
debug1: Will attempt key: /c/Users/uchin/.ssh/id_xmss
debug1: Will attempt key: /c/Users/uchin/.ssh/id_dsa
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>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug1: Next authentication method: publickey
debug1: Offering public key: /c/Users/uchin/.ssh/id_rsa RSA SHA256:ryU3w/a2yayTwFk3eNMI7NoyEugbQgYMrulXT9f/oeY
debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug1: Trying private key: /c/Users/uchin/.ssh/id_ecdsa
debug1: Trying private key: /c/Users/uchin/.ssh/id_ecdsa_sk
debug1: Trying private key: /c/Users/uchin/.ssh/id_ed25519
debug1: Trying private key: /c/Users/uchin/.ssh/id_ed25519_sk
debug1: Trying private key: /c/Users/uchin/.ssh/id_xmss
debug1: Trying private key: /c/Users/uchin/.ssh/id_dsa
debug1: Next authentication method: keyboard-interactive
debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug1: Next authentication method: password
git@github.com\'s password:
Connection closed by 223.75.236.241 port 22

我想知道如何让它工作,谢谢

    标签: git ssh


    【解决方案1】:

    ssh 输出并不表明GitHub 服务器接受您的密钥.所以请检查您是否正确上传了等效的公钥。

    您可以通过访问网址验证公钥是否上传成功:https://github.com/&lt;your_github_username&gt;.keys

    例如,假设您的用户名是uchin,那么您可以在https://github.com/uchin.keys 看到您的所有公钥

    如果密钥不匹配,则重新上传公钥。如果不是,请重新运行ssh -vvv git@github.com,并在此处分享输出。

    【讨论】: