github提示Permission denied (publickey),如何才能解决?

$ git clone [email protected]:gogo/protobuf.git
Cloning into 'protobuf'...
The authenticity of host 'github.com (13.229.188.59)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,13.229.188.59' (RSA) to the list of known hosts.
[email protected]: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

github中自己账户settings-SSH and GPG keys-new ssh key 如图

回到需要下载源码的机器终端

敲入命令,一路回车

#ssh-keygen -t rsa   

然后进入/root/.ssh/ 目录 查看

取出公钥,复制粘贴github中的key中,保存即可

#cat id_rsa.pub

测试,成功

#ssh -T [email protected]
Hi kylePan! You've successfully authenticated, but GitHub does not provide shell access.

我的操作命令如下

[root@VM_171_105_centos src]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
c8:b9:17:bf:e7:9b:8b:ba:9f:e1:23:0d:1c:6a:64:45 root@VM_171_105_centos
The key's randomart image is:
+--[ RSA 2048]----+
|       .E        |
|        .        |
|       .         |
|     .oo.        |
|     o+oS.       |
|      o.oo       |
|     .. .oo      |
|       ...o=..   |
|        o=*+=o   |
+-----------------+
[root@VM_171_105_centos src]# ssh -T [email protected]
Permission denied (publickey).
[root@VM_171_105_centos src]# cd /root/.ssh/
[root@VM_171_105_centos .ssh]# ls
authorized_keys  id_rsa  id_rsa.pub  known_hosts
[root@VM_171_105_centos .ssh]# cat id_rsa.pub 
ssh-rsa AAAAB3AAABIwAAAQEAzVPno/Cm5ApGGMP8YjituJGegOCq7TVKVECehWog9hTfC0Z5PMsf5OWkWvUZ85nFJBuwhMszxkjFSd7e6INYJ42WfGKxPXm7ZoOQxkBZAetUUaNvDhCKZCdLNHWGde8gaX84i39JKWgwYrzX9Y1T+bDI1cJiUuNN6Xr8x4ZkMm4e+LugYtVSKGZKz7zLcp1mXQszh9mWM08/yyRq/CdTEly1ghojUDUNFTzyk6VQz/rzMFoiVuwbYlQasqdR4xIzvnIjfBrtSP4z+qdD+wZFvSABnFClXH0nJEaaKX9EdJpi2ezvLvAblDg371J
[root@VM_171_105_centos .ssh]# ssh -T [email protected]
Hi kylePan! You've successfully authenticated, but GitHub does not provide shell access.

猜你喜欢

转载自my.oschina.net/u/1377923/blog/1822038
今日推荐