git问题之[email protected]: Permission denied (publickey).

文章目录

  • 1.问题描述
  • 2.解决方案
    • 2.1.先验证一下是否真的没有权限:ssh -T [email protected]
    • 2.2.重新生成公私钥:一路回车即可
    • 2.3.查看上面的公钥id_rsa.pub
    • 2.4.将上面的公钥配置到我们的GitHub仓库中
    • 2.5.再验证一下是否真的没有权限:ssh -T [email protected]

1.问题描述

localhost:apache-commons gaoxinfu$ git clone git@github.com:apache/commons-configuration.git
Cloning into 'commons-configuration'...
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
localhost:apache-commons gaoxinf

2.解决方案

2.1.先验证一下是否真的没有权限:ssh -T [email protected]

localhost:.ssh gaoxinfu$ ssh -T git@github.com
git@github.com: Permission denied (publickey).
localhost:.ssh gaoxinfu$ ssh -vT git@github.com
OpenSSH_7.9p1, LibreSSL 2.7.3
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 48: Applying options for *
debug1: Connecting to github.com [52.74.223.119] port 22.
debug1: Connection established.
debug1: identity file /Users/gaoxinfu/.ssh/id_rsa type -1
debug1: identity file /Users/gaoxinfu/.ssh/id_rsa-cert type -1
debug1: identity file /Users/gaoxinfu/.ssh/id_dsa type -1
debug1: identity file /Users/gaoxinfu/.ssh/id_dsa-cert type -1
debug1: identity file /Users/gaoxinfu/.ssh/id_ecdsa type -1
debug1: identity file /Users/gaoxinfu/.ssh/id_ecdsa-cert type -1
debug1: identity file /Users/gaoxinfu/.ssh/id_ed25519 type -1
debug1: identity file /Users/gaoxinfu/.ssh/id_ed25519-cert type -1
debug1: identity file /Users/gaoxinfu/.ssh/id_xmss type -1
debug1: identity file /Users/gaoxinfu/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_7.9
debug1: Remote protocol version 2.0, remote software version babeld-cc5efb01
debug1: no match: babeld-cc5efb01
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: 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: Server host key: ssh-rsa SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8
debug1: Host 'github.com' is known and matches the RSA host key.
debug1: Found key in /Users/gaoxinfu/.ssh/known_hosts:5
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: Will attempt key: /Users/gaoxinfu/.ssh/id_rsa 
debug1: Will attempt key: /Users/gaoxinfu/.ssh/id_dsa 
debug1: Will attempt key: /Users/gaoxinfu/.ssh/id_ecdsa 
debug1: Will attempt key: /Users/gaoxinfu/.ssh/id_ed25519 
debug1: Will attempt key: /Users/gaoxinfu/.ssh/id_xmss 
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<ssh-ed25519-cert-v01@openssh.com,ecdsa-sha2-nistp521-cert-v01@openssh.com,ecdsa-sha2-nistp384-cert-v01@openssh.com,ecdsa-sha2-nistp256-cert-v01@openssh.com,rsa-sha2-512-cert-v01@openssh.com,rsa-sha2-256-cert-v01@openssh.com,ssh-rsa-cert-v01@openssh.com,ssh-dss-cert-v01@openssh.com,ssh-ed25519,ecdsa-sha2-nistp521,ecdsa-sha2-nistp384,ecdsa-sha2-nistp256,rsa-sha2-512,rsa-sha2-256,ssh-rsa,ssh-dss>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Trying private key: /Users/gaoxinfu/.ssh/id_rsa
debug1: Trying private key: /Users/gaoxinfu/.ssh/id_dsa
debug1: Trying private key: /Users/gaoxinfu/.ssh/id_ecdsa
debug1: Trying private key: /Users/gaoxinfu/.ssh/id_ed25519
debug1: Trying private key: /Users/gaoxinfu/.ssh/id_xmss
debug1: No more authentication methods to try.
git@github.com: Permission denied (publickey).

2.2.重新生成公私钥:一路回车即可

localhost:.ssh gaoxinfu$ ssh-keygen -t rsa -b 4096 -C "[email protected]"
localhost:.ssh gaoxinfu$ ssh-keygen -t rsa -b 4096 -C "[email protected]"
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/gaoxinfu/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /Users/gaoxinfu/.ssh/id_rsa.
Your public key has been saved in /Users/gaoxinfu/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:8nUalK939UGmj8tX8Ts98UWrQ6Vo274ZCJhVKSzvAjs gaoxinfu@aliyun.com
The key's randomart image is:
+---[RSA 4096]----+
|        .  ..    |
|       . o.o     |
|        o.+    o |
|     .  +o .  +o.|
|      +oS.o +.oo=|
|     E + o.B.oo+*|
|      . o +.=oo.O|
|           o.=+=o|
|            .*+ o|
+----[SHA256]-----+
localhost:.ssh gaoxinfu$ 
localhost:.ssh gaoxinfu$ 
localhost:.ssh gaoxinfu$ pwd
/Users/gaoxinfu/.ssh
localhost:.ssh gaoxinfu$ ls -la
total 24
drwx------    5 gaoxinfu  staff   160  9  8 16:59 .
drwxr-xr-x@ 128 gaoxinfu  staff  4096  9  8 16:54 ..
-rw-------    1 gaoxinfu  staff  3389  9  8 16:59 id_rsa
-rw-r--r--    1 gaoxinfu  staff   745  9  8 16:59 id_rsa.pub
-rw-r--r--    1 gaoxinfu  staff  2553  1 25  2020 known_hosts

2.3.查看上面的公钥id_rsa.pub

localhost:.ssh gaoxinfu$ cat id_rsa.pub 
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDrEhw2a+HqiZ7T2KjcBHpdd6UCdiTdzqOU1ApvcR5QFecqGj0GxI07rzriDcKiqkJeCfAxcjAYolZmAvcg4b5cCtOXAFiFdfTKqUCFRP4PzlNmXA2mo0ml86wyy3DehKCfe8mneC88Wk7bOGAptLQsBh6wWPj2FsbQXtLlsQm8lz01n8dO3fNd7V72UVyZq+0FJ62doQgQEoampBnQ+wf8wkMSE/D3123123123131231fmBvWoN+gRW0qZJv5MoAUIctEbaKjnSEe/ptGQF+c3FADcMcXJ9m0x5Se57RPY1pxNQIvt9yd3If3XN4E2twoEzUa/Q8tH65cpoeHNKkdybUAaG25S6peXEexpFr3EFQe6ROOxa0OtG6z/AjEEdMxy/qDha3O8230ULHOBq1tTtg6DzmcR9q9KkEKBSOhW0hx47wWFuFGTJN3BgBBOUqsFD798XTqOt/XlFlsHpxzJ3B7m535pzL+JTPUDFZfvTG63DgpEVvBMMutPa0qjB0mS98YKoIPZ35SJF0Pui44UvPBEN3v2kBjIJkbb4snEXQHt6uLd3Bf/NSSRzbn8Ku/SyTzqnhK0o99GrzPQadT/ze3MBGw1+iGVeHfLEgAs0bZS9vK4c9HVf+5MP8e3FloZF4WlekKgqjCCx9ESwc+716ZCZc52gaiB+XFDk0qzQ== gaoxinfu@aliyun.com
localhost:.ssh gaoxinfu$ ssh -vT git@github.com

2.4.将上面的公钥配置到我们的GitHub仓库中

git问题之git@github.com: Permission denied (publickey)._第1张图片
git问题之git@github.com: Permission denied (publickey)._第2张图片
git问题之git@github.com: Permission denied (publickey)._第3张图片
git问题之git@github.com: Permission denied (publickey)._第4张图片

git问题之git@github.com: Permission denied (publickey)._第5张图片

2.5.再验证一下是否真的没有权限:ssh -T [email protected]

localhost:.ssh gaoxinfu$ ssh -vT git@github.com
OpenSSH_7.9p1, LibreSSL 2.7.3
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 48: Applying options for *
debug1: Connecting to github.com [13.229.188.59] port 22.
debug1: Connection established.
debug1: identity file /Users/gaoxinfu/.ssh/id_rsa type 0
debug1: identity file /Users/gaoxinfu/.ssh/id_rsa-cert type -1
debug1: identity file /Users/gaoxinfu/.ssh/id_dsa type -1
debug1: identity file /Users/gaoxinfu/.ssh/id_dsa-cert type -1
debug1: identity file /Users/gaoxinfu/.ssh/id_ecdsa type -1
debug1: identity file /Users/gaoxinfu/.ssh/id_ecdsa-cert type -1
debug1: identity file /Users/gaoxinfu/.ssh/id_ed25519 type -1
debug1: identity file /Users/gaoxinfu/.ssh/id_ed25519-cert type -1
debug1: identity file /Users/gaoxinfu/.ssh/id_xmss type -1
debug1: identity file /Users/gaoxinfu/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_7.9
debug1: Remote protocol version 2.0, remote software version babeld-cc5efb01
debug1: no match: babeld-cc5efb01
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: 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: Server host key: ssh-rsa SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8
debug1: Host 'github.com' is known and matches the RSA host key.
debug1: Found key in /Users/gaoxinfu/.ssh/known_hosts:5
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: Will attempt key: /Users/gaoxinfu/.ssh/id_rsa RSA SHA256:8nUalK939UGmj8tX8Ts98UWrQ6Vo274ZCJhVKSzvAjs
debug1: Will attempt key: /Users/gaoxinfu/.ssh/id_dsa 
debug1: Will attempt key: /Users/gaoxinfu/.ssh/id_ecdsa 
debug1: Will attempt key: /Users/gaoxinfu/.ssh/id_ed25519 
debug1: Will attempt key: /Users/gaoxinfu/.ssh/id_xmss 
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<ssh-ed25519-cert-v01@openssh.com,ecdsa-sha2-nistp521-cert-v01@openssh.com,ecdsa-sha2-nistp384-cert-v01@openssh.com,ecdsa-sha2-nistp256-cert-v01@openssh.com,rsa-sha2-512-cert-v01@openssh.com,rsa-sha2-256-cert-v01@openssh.com,ssh-rsa-cert-v01@openssh.com,ssh-dss-cert-v01@openssh.com,ssh-ed25519,ecdsa-sha2-nistp521,ecdsa-sha2-nistp384,ecdsa-sha2-nistp256,rsa-sha2-512,rsa-sha2-256,ssh-rsa,ssh-dss>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering public key: /Users/gaoxinfu/.ssh/id_rsa RSA SHA256:8nUalK939UGmj8tX8Ts98UWrQ6Vo274ZCJhVKSzvAjs
debug1: Server accepts key: /Users/gaoxinfu/.ssh/id_rsa RSA SHA256:8nUalK939UGmj8tX8Ts98UWrQ6Vo274ZCJhVKSzvAjs
debug1: Authentication succeeded (publickey).
Authenticated to github.com ([13.229.188.59]:22).
debug1: channel 0: new [client-session]
debug1: Entering interactive session.
debug1: pledge: network
debug1: Sending environment.
debug1: Sending env LANG = zh_CN.UTF-8
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
Hi gaoxinfu! 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.6 seconds
Bytes per second: sent 5602.7, received 4421.1
debug1: Exit status 1
localhost:.ssh gaoxinfu$ 

你可能感兴趣的:(github,git)