git报错:Permission denied (publickey). fatal: Could not read from remote repository.

作者:王老头 
出处:http://www.cnblogs.com/wmr95/p/7852832.html
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,并在文章页面明显位置给出原文链接,否则,作者将保留追究法律责任的权利。

ternimal下出现下面错误:

Permissiondenied (publickey).

fatal:Could not read from remote repository.

Pleasemake sure you have the correct access rights

and the repository exists.

原因是由于你在本地(或者服务器上)没有生成ssh key,可执行cd ~/.ssh ls来查看,此时查不到内容

下面记录解决办法:

1.首先,如果你没有ssh key的话,在ternimal下输入命令:ssh-keygen -t rsa -C "[email protected]", [email protected]改为自己的邮箱即可,途中会让你输入密码啥的,不需要管,一路回车即可,会生成你的ssh key。(如果重新生成的话会覆盖之前的ssh key。)

  

  2.然后再ternimal下执行命令:

  ssh -v [email protected] 

  最后两句会出现:

  No more authentication methods to try.  

  Permission denied (publickey).

  3.这时候再在ternimal下输入:

  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;

  4.接着再输入:

  ssh-add ~/.ssh/id_rsa

  这时候应该会提示:

  Identity added: ...(这里是一些ssh key文件路径的信息)

  (注意)如果出现错误提示:

  Could not open a connection to your authentication agent.

  请执行命令:eval `ssh-agent -s`后继续执行命令 ssh-add ~/.ssh/id_rsa,这时候一般没问题啦。

  5.打开你刚刚生成的id_rsa.pub,将里面的内容复制,进入你的github账号,在settings下,SSH and GPG keys下new SSH key,title随便取一个名字,然后将id_rsa.pub里的内容复制到Key中,完成后Add SSH Key。

  6.最后一步,验证Key

  在ternimal下输入命令:

  ssh -T [email protected]

  提示:Hi xxx! You've successfully authenticated, but GitHub does not provide shell  access.

  这时候你的问题就解决啦,可以使用命令 git clone --recursive [email protected]:peiyunh/tiny.git 去下载你的代码啦。

发布了9 篇原创文章 · 获赞 0 · 访问量 218

猜你喜欢

转载自blog.csdn.net/mlh532354163/article/details/97976792