今天在ubuntu下安装部署Hexo Blog的时候,遇到一个不能Deploy到github的错误:
1 |
|
搜索了一阵子,发现可以清理key-pari的教程。教程如下。
重置当前电脑的key-pair
- 清除所有的key-pair
ssh-add -D
rm -r ~/.ssh
-
删除github中的public-key
-
重新生成ssh密钥对
1
2
3ssh-keygen -t rsa -C "youremail@email.com"
chmod 0700 ~/.ssh
chmod 0600 ~/.ssh/id_rsa*
你可以用通过命令ssh-add -l
查看当前key agent的key list
如果生成key的时候选择了自定义的key名字,可以使用下面的命令添加到key agent里面:
ssh-add ~/.ssh/YOUR-PUBLIC-KEY-NAME
- 在Github添加公钥public-key
在终端运行 xclip -sel ~/.ssh/id_rsa.pub
把公钥内容复制到剪贴板
然后在github上添加公钥
- 校验是否能够连同Github
ssh -T git@github.com
正常的话,github会返回你的登陆用户名:
1 |
|
解决Permission issue
我发现我错误的原因是,先用这招来生成 id_rsa.pub
ssh-keygen -t rsa -b 4096 -C "some@email.com"
告诉我没有权限,于是我加了sudo
操作,结果文件生成到了根目录而不是家目录下:
/var/root/.ssh/id_rsa/var/root/.ssh/id_rsa.pub
正确的做法是把根目录下的复制到家目录下:
1 | sudo cp /var/root/.ssh/id_rsa /Users/michael/.ssh/id_rsa |
然后测试:
ssh -T git@github.com
Hi michael! You've successfully authenticated, but GitHub does not provide shell access.
参考资源
Adding a new SSH key to your GitHub account
Generating a new SSH key and adding it to the ssh-agent