github clone "Permission denied (publickey). fatal: Could not read from remote repository."

LZ用git不久,第一次从github clone项目遇见一下问题

$ git clone git@github.com:xiaolongzuo/niubi-job.gitCloning into 'niubi-job'...Permission denied (publickey).fatal: Could not read from remote repository.

解决办法:

1.ssh -v git@github.com

   测试ssh连接是否成功,如LZ显示如下:

$ ssh -v git@github.com

OpenSSH_7.3p1, OpenSSL 1.0.2j 26 Sep 2016

debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to github.com [192.30.253.113] port 22.
debug1: Connection established.
debug1: identity file /c/Users/Administrator/.ssh/id_rsa type 1
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/Administrator/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/Administrator/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/Administrator/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/Administrator/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/Administrator/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/Administrator/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/Administrator/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.3
debug1: Remote protocol version 2.0, remote software version libssh-0.7.0
debug1: no match: libssh-0.7.0
debug1: Authenticating to github.com:22 as 'git'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256@libssh.org
debug1: kex: host key algorithm: ssh-rsa
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 /c/Users/Administrator/.ssh/known_hosts:1
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /c/Users/Administrator/.ssh/id_rsa
debug1: Authentications that can continue: publickey
debug1: Trying private key: /c/Users/Administrator/.ssh/id_dsa
debug1: Trying private key: /c/Users/Administrator/.ssh/id_ecdsa
debug1: Trying private key: /c/Users/Administrator/.ssh/id_ed25519
debug1: No more authentication methods to try.
Permission denied (publickey).


2. ssh-agent -s

     

$ ssh-agent -s
SSH_AUTH_SOCK=/tmp/ssh-GTpABX1a05qH/agent.404; export SSH_AUTH_SOCK;
SSH_AGENT_PID=13144; export SSH_AGENT_PID;
echo Agent pid 13144;


3. ssh-add ~/.ssh/id_rsa

    

$ ssh-add ~/.ssh/id_rsa
Could not open a connection to your authentication agent.
 LZ这一步报错了,继续执行:eval `ssh-agent -s`

 无错请忽略以下步骤

$ eval `ssh-agent -s`
Agent pid 24460

   再次执行ssh-add ~/.ssh/id_rsa

$ ssh-add ~/.ssh/id_rsa
Identity added: /c/Users/Administrator/.ssh/id_rsa (/c/Users/Administrator/.ssh/id_rsa)


4.将客户端生成的key添加到github账户


   首先使用 clip < ~/.ssh/id_rsa.pub  或者文本编辑拷贝id_rsa.pub文本内容

    到github右上角账户管理-Setting下面找到左侧“SSH and GPG keys”菜单,接着点击“Add SSH key”,在"title"栏输入一个自己喜欢的标题,“key”栏中粘贴刚刚复制的公钥内容,最后点击“Add key”按钮。


5.最后一步,验证key

$ ssh -T git@github.com
Hi JsonJu! You've successfully authenticated, but GitHub does not provide shell  access.

接下来就可以愉快的去clone github上优秀的项目了。



 

   
 

  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
极狐 Permission denied (publickey). fatal: Could not read from remote repository. 这个错误通常是由于没有正确的 SSH 密钥或者没有将公钥添加到 Github 帐户中所致。要解决这个问题,你可以按照以下步骤进行操作: 1. 确保已经生成了正确的 SSH 密钥。你可以使用命令 `ls -al ~/.ssh` 来检查是否已经生成了 SSH 密钥。如果没有生成,你可以使用命令 `ssh-keygen -t rsa -b 4096 -C "[email protected]"` 来生成一个新的 SSH 密钥。 2. 确保已经将公钥添加到了 Github 帐户中。你可以使用命令 `cat ~/.ssh/id_rsa.pub` 来获取你的公钥内容,然后将其添加到 Github 帐户的***。如果看到消息 "Hi [username]! You've successfully authenticated, but GitHub does not provide shell access.",那么表示你已经成功通过 SSH 访问 Github。否则,可能还需要检查一下生成的 SSH 密钥是否正确。 通过以上步骤,你应该能够解决极狐 Permission denied (publickey). fatal: Could not read from remote repository 这个错误。如果问题仍然存在,可能还需要进一步检查 SSH 配置、网络连接等方面的问题。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [Permission denied (publickey). fatal: Could not read from remote repository.](https://blog.csdn.net/liulanba/article/details/129742145)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值