git push(clone)失败报错:Permission denied (publickey). fatal: Could not read from remote repository.
而当我执行git push -u origin master这条语句的时候,出现错误: Permissiondenied (publickey). fatal:Could not read from remote repository. Pleasemake sure you have the correct access rights and the repository...
而当我执行git push -u origin master这条语句的时候,出现错误:
Permissiondenied (publickey).
fatal:Could not read from remote repository.
Pleasemake sure you have the correct access rights
and the repository exists.
你在本地(或者服务器上)没有生成ssh key,你可以在git bash中执行:
cd ~/.ssh ls来查看是否有文件id_rsa以及文件id_rsa.pub,如下图所示:(我的已经生成了,所以我ls后会显示。)
下面记录下解决办法:
1.首先,如果你没有ssh key的话,在ternimal下输入命令:ssh-keygen -t rsa -C "914559@qq.com", 途中一路回车即可,会生成你的ssh key。(如果重新生成的话会覆盖之前的ssh key。)
2.然后再git bash下执行命令:
ssh -v git@github.com
最后两句会出现:
No more authentication methods to try.
Permission denied (publickey).
3.这时候再在git bash下输入:
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 git@github.com
提示:Hi xxx! You've successfully authenticated, but GitHub does not provide shell access.
开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!
更多推荐
所有评论(0)