Ubuntu 用ssh免密码登录github失败解决 (去坑版)

http://blog.csdn.net/isinstance/article/details/53690467

前言:因为笔者有两个开发环境,一个是Ubuntu16.04的虚拟机,一个是Linux Mint 18的物理机,然后Mint的好弄,基本就是按照教程来就行了,就是这个Ubuntu的有点逻辑问题,什么问题,下面说

第一步肯定是生成id_rsa.pub啦

Github官方的做法是这样的

ssh-keygen -t rsa -b 4096 -C "you_email@mail.com"

但是如果你这样在Ubuntu上做了,后面你test链接的时候就会

code@code-VirtualBox:~/Downloads$ ssh -T git@github.com
The authenticity of host 'github.com (192.30.253.113)' can't be established.
RSA key fingerprint is SHA256:------------------------.
Are you sure you want to continue connecting (yes/no)? yes
Failed to add the host to the list of known hosts (/home/code/.ssh/known_hosts).
Load key "/home/code/.ssh/id_rsa": Permission denied
Permission denied (publickey).

没错,看到了没有,Permission denied

然后又看到这个P D, 加sudo

code@code-VirtualBox:~/Downloads$ sudo ssh -T git@github.com
Permission denied (publickey).

为什么会这样呢?

因为第一个是因为你没有权限去用/home/code/.ssh/下的pub公钥

加了sudo之后,你变root了,现在调用的是/root/.ssh/选的pub公钥了

所以这里有个逻辑漏洞

第二步解决

直接用/root/.ssh/下的公钥

先生成

code@code-VirtualBox:~/.ssh$ sudo ssh-keygen -t rsa -b 4096 -C "xxx@yyy.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
/root/.ssh/id_rsa already exists.
Overwrite (y/n)? y
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:
SHA256:-----------------------xxx@yyy.com
The key's randomart image is:
+---[RSA 4096]----+
|                 |
|                 |
|     这里省略     |
|                 |
|                 |
|                 |
|                 |
|                 |
|                 |
+----[SHA256]-----+

然后你是进不去/root/.ssh/

方法就是把这pub铐出来

code@code-VirtualBox:~/.ssh$ cd /root/.ssh/
bash: cd: /root/.ssh/: Permission denied

我是把它铐到Downloads目录下

code@code-VirtualBox:~/.ssh$ sudo cp /root/.ssh/id_rsa.pub /home/code/Downloads/

然后用gedit打开,复制到github上的ssh-key哪里

然后测试一下

code@code-VirtualBox:~/.ssh$ sudo ssh -T git@github.com
Hi SuperSuperSuperSuper5! You've successfully authenticated, but GitHub does not provide shell access.

说明我们链接上了,测试成功,以后push代码的时候,加上sudo就行了

ok,本次课程到此结束

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值