亲测解决[git 中github clone "Permission denied (publickey). fatal: Could not read from remote repository.

@亲测解决git 中github clone "Permission denied (publickey). fatal: Could not read from remote repository."TOC

第一步
我们需要在github创建一个账户,然后在终端输入
ssh-keygen -t rsa -C “username”(引号一定是英文状态下的,否则会报错),(username替换成github的用户名称)
如果执行成功。返回

Generating public/private rsa key pair.

Enter file in which to save the key (/Users/username/.ssh/id_rsa):
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/username/.ssh/id_rsa):

首先,说明一下,这里的username是你电脑上的用户名

然后,在这里就是设置存储地址了.我们直接按回车,会出现一下两种情况的一种:

(1)如果正常运行的话,会出现

Enter passphrase (empty for no passphrase):

然后我们直接回车

(2)有的时候我们可能会出现

/Users/your username/.ssh/id_rsa already exists.

Overwrite (y/n)?
这说明你已经设置了存储地址,我们输入“y”覆盖

Overwrite (y/n)? y

回车

上面的任意两种情况之后,会出现

Enter same passphrase again:
再次回车,这时候你会看见:

Your identification has been saved in /home/omnisky/.ssh/id_rsa.
Your public key has been saved in /home/omnisky/.ssh/id_rsa.pub.

The key fingerprint is:

58:42:8b:58:ad:4b:b5:b9:6d:79:bf:8c:f9:e2:2b:ed username

The key’s randomart image is:

±-[ RSA 2048]----+

| … |

| o oo. |

| . .ooo. |

| o o+ |

| . …oS. |

| . . + . |

| . o . |

| . o+. |

| +E++. |

±----------------+

这说明SSH key就已经生成了。文件目录就是:/Users/username/.ssh/id_rsa.pub.
直接在目录底下我们是找不到id_rsa.pub的文件,需要通过在终端执行cat命令
查看文件的内容:

cat /home/omnisky/.ssh/id_rsa.pub (文件目录就是上面Your public key has been saved in /home/omnisky/.ssh/id_rsa.pub出现的,加粗的就是位置)

这时候会看见:

ssh-rsa AAAAB3NzaC1yc2。。。。。。。。。

第二步(参照链接https://jingyan.baidu.com/album/d2b1d102dff17b5c7e37d4aa.html?picindex=2)

用我们之前注册的git账户,登录进去,点击右上方图像位置,再点setting,进入setting页面,选择左侧的“SSH and GPG keys”这一项,然后点击右侧的“New SSH key”按钮新建一个SSH key,

最后把之前生成的key(ssh-rsa AAAAB3NzaC1yc2。。。。。。。。。)复制到这里,点击“Add SSH key”按钮即可。
第三步
1.在终端输入测试:ssh git@github.com
出现:sign_and_send_pubkey: signing failed: agent refused operation
Permission denied (publickey).
2.在终端输入:ssh -v git@github.com
出现:OpenSSH_7.2p2 Ubuntu-4ubuntu2.8, OpenSSL 1.0.2g 1 Mar 2016
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to github.com [13.229.188.59] port 22.
debug1: Connection established.
debug1: identity file /home/omnisky/.ssh/id_rsa type 1
debug1: key_load_public: No such file or directory
debug1: identity file /home/omnisky/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/omnisky/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/omnisky/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/omnisky/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/omnisky/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/omnisky/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/omnisky/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.8
debug1: Remote protocol version 2.0, remote software version babeld-ad2b1500
debug1: no match: babeld-ad2b1500
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: rsa-sha2-512
debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: compression: none
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: 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 /home/omnisky/.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,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: Offering RSA public key: /home/omnisky/.ssh/id_rsa
debug1: Server accepts key: pkalg ssh-rsa blen 279
sign_and_send_pubkey: signing failed: agent refused operation
debug1: Offering RSA public key: /home/omnisky/.ssh/id_rsa
debug1: Authentications that can continue: publickey
debug1: Offering RSA public key: /home/omnisky/.ssh/id_rsa
debug1: Authentications that can continue: publickey
debug1: Trying private key: /home/omnisky/.ssh/id_dsa
debug1: Trying private key: /home/omnisky/.ssh/id_ecdsa
debug1: Trying private key: /home/omnisky/.ssh/id_ed25519
debug1: No more authentication methods to try.
Permission denied (publickey).
3. 在终端输入:ssh-agent -s
出现:SSH_AUTH_SOCK=/tmp/ssh-xdUf0A7XiwqE/agent.19130; export SSH_AUTH_SOCK;
SSH_AGENT_PID=19131; export SSH_AGENT_PID;
echo Agent pid 19131;
4.在终端输入:ssh-add ~/.ssh/id_rsa
出现:Identity added: /home/omnisky/.ssh/id_rsa (/home/omnisky/.ssh/id_rsa)
4. 在终端输入:ssh -T git@github.com
现在就是见证奇迹的时刻了,出现:
Hi nietingting! You’ve successfully authenticated, but GitHub does not provide shell access.
接下来,我们就能愉快的下载clone github上优秀的项目了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值