Linux下git检测密钥ssh-T报Permission denied解决办法

lh@lh-virtual-machine:~$ sudo ssh -T git@github.com
The authenticity of host 'github.com (52.74.223.119)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,52.74.223.119' (RSA) to the list of known hosts.
Permission denied (publickey)
  • 如图,当使用ssh -T命令查询密钥是否可用时报错。

  • 解决办法:
                     

  1. 原因分析:本人在使用git链接仓库时,重复创建了密钥key,即~/.ssh/id_rsa.pub已存在,此时继续使用命令: “ssh-keygen -t rsa -C "git的邮箱" ” 创建密钥时会提示是否覆盖
    lh@lh-virtual-machine:~$ ssh-keygen -t rsa -C "xxx@xx.com"
    Generating public/private rsa key pair.
    Enter file in which to save the key (/home/lh/.ssh/id_rsa): 
    /home/lh/.ssh/id_rsa already exists.
    Overwrite (y/n)? y
    Enter passphrase (empty for no passphrase): 
    Enter same passphrase again: 
    Saving key "/home/lh/.ssh/id_rsa" failed: Permission denied

    确认覆盖提示没有权限,于是自己使用了sudo ssh-keygen -t rsa -C "xxx@xx.com"
    但是保存key的默认路径却变成了如下:

    Enter file in which to save the key (/root/.ssh/id_rsa):

    继续回车,于是创建的key被保存到了/root/.ssh/id_rsa,而在查看key的时候复制了 /home/lh/.ssh/id_rsa下的key到github的仓库。

  2. 探索发现:

      在执行ssh -T命令时加sudo,系统执行的是/root/.ssh/id_rsa下的key去匹配;

      不加sudo,系统执行的是/home/lh/.ssh/id_rsa下的key;

  3. lh@lh-virtual-machine:~$ cat .ssh/id_rsa.pub 
    ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCd1dmFkr8fXsVha+5ZprIJ/ox11Ghx3TtjI4h8TpG7wePIWjHSJ/v6jm6u5GA4/CwiBNVd7eQyNvjkwfxWLWnoXkEPYV/9Q3bEFauOtiHfbZn9osn2hBp2xKjX6cR3mok0xsBfgj14hbFoEXRwskKzyYlwWgP6ignPvkWVYX+hR2Z8DSnMJfn6xKbQOTR9WirNMOeXT+PDvyuLnfHY0E11yN+E1tZYs+FW/RhHXYT1PDXHL7mMjZ/WFOn9PxzO7TFYR2b2KQQgaETx1931cKInM0KDJLdKG5B1tSv/q5/d8jTyzPsCRQzyG7CEKOPtsBFQxLDraOThv0qOVu9kpGCX 912363729@qq.com
    lh@lh-virtual-machine:~$ ssh -T git@github.com
    The authenticity of host 'github.com (52.74.223.119)' can't be established.
    RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
    Are you sure you want to continue connecting (yes/no)? yes
    Warning: Permanently added 'github.com,52.74.223.119' (RSA) to the list of known hosts.
    Hi lihengsss! You've successfully authenticated, but GitHub does not provide shell access.

    使用~/下的key,添加到github上,不加sudo执行ssh -T,检查密钥为可用。

             

 

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值