今天在linux下使用git push时发生了以下错误:
[root@localhost QuXuan]# git push origin master
Permission denied (publickey).
fatal: The remote end hung up unexpectedly
通过对问题的具体描述找到了官方的解决方式:
https://help.github.com/articles/generating-ssh-keys/#platform-linux
我再以我的具体过程为例:
首先查看公钥:
[root@localhost QuXuan]# ls -al ~/.ssh
total 12
drwx——. 2 root root 4096 Mar 10 10:51 .
dr-xr-x—. 7 root root 4096 Mar 10 10:50 ..
-rw-r–r–. 1 root root 803 Mar 10 10:53 known_hosts
这里并没有id_rsa相关文件。
那么就得自己设定一个:
[root@localhost QuXuan]# ssh-keygen -t rsa -C “opk_yang_bin@126.com”
“”引号内为自己github账号的邮箱。
当显示:
Enter file in which to save the key (/root/.ssh/id_rsa):
只需按下回车ENTER便可。
之后显示:
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
输入github密码后再次确认之后,公钥生成:
[root@localhost /]# ls -al ~/.ssh
total 20
drwx——. 2 root root 4096 Mar 10 11:08 .
dr-xr-x—. 7 root root 4096 Mar 10 11:21 ..
-rw——-. 1 root root 1751 Mar 10 11:08 id_rsa
-rw-r–r–. 1 root root 402 Mar 10 11:08 id_rsa.pub
-rw-r–r–. 1 root root 803 Mar 10 10:53 known_hosts
我们复制后id_rsa.pub内容。
打开我们的github主页。
选择我们的settings->.ssh keys->add ssh key.
key的title随你定,key的内容便是我们复制的id_rsa.pub的内容,提交后即可完成。
再回到我们的系统,使用命令:
[root@localhost QuXuan]# ssh -T git@github.com
Enter passphrase for key ‘/root/.ssh/id_rsa’:
Hi XXXXXX! You’ve successfully authenticated, but GitHub does not provide shell access.
如果输入密码后,XXXXXX为你们用户名,表示已经设置成功。
接下来便git push成功。
github首页刷新时便能看到项目已提交上线。
对git的学习可以在慕课网上找寻到课程。如果能每天都在github上贡献自己的代码,编程能力一定日益见长,与君共勉。