git@github.com: Permission denied (publickey).

首先用 ssh -vT git@github.com 测试一下,会去你用户目录下面找公钥文件:

debug1: Will attempt key: /Users/ligengze/.ssh/id_rsa
debug1: Will attempt key: /Users/ligengze/.ssh/id_dsa
debug1: Will attempt key: /Users/ligengze/.ssh/id_ecdsa
debug1: Will attempt key: /Users/ligengze/.ssh/id_ed25519
debug1: Will attempt key: /Users/ligengze/.ssh/id_xmss
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<ssh-ed25519,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,ssh-rsa,rsa-sha2-512,rsa-sha2-256,ssh-dss>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Trying private key: /Users/ligengze/.ssh/id_rsa
debug1: Trying private key: /Users/ligengze/.ssh/id_dsa
debug1: Trying private key: /Users/ligengze/.ssh/id_ecdsa
debug1: Trying private key: /Users/ligengze/.ssh/id_ed25519
debug1: Trying private key: /Users/ligengze/.ssh/id_xmss
debug1: No more authentication methods to try.
git@github.com: Permission denied (publickey).
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

类似这样信息,这说明/User/用户名/.ssh/ 下面去寻找公钥文件,当前用户目录下面的确没有公钥文件,解决办法:
切换到/User/用户名/.ssh/ 下面:

cd /User/xxx/.ssh/(这是问题的关键,不是什么目录都可以)
  • 1

使用

ssh-keygen -t rsa -b 4096 -C "Git邮箱@qq.com"
  • 1

一路回车下去
在.ssh/下面会生成isa.pub 文件
复制里面的内容在github 新建ssh key
重新使用ssh -vT git@github.com

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: Sending env LC_CTYPE = zh_CN.UTF-8
Hi xiyuan1223! You've successfully authenticated, but GitHub does not provide shell access.
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
debug1: channel 0: free: client-session, nchannels 1
Transferred: sent 3504, received 2484 bytes, in 0.8 seconds
Bytes per second: sent 4271.0, received 3027.7
debug1: Exit status 1
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

okay!

 

posted on 2019-07-15 22:04  qqhfeng16  阅读(454)  评论(0编辑  收藏  举报