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命令查询密钥是否可用时报错。
-
解决办法:
- 原因分析:本人在使用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的仓库。
- 探索发现:
在执行ssh -T命令时加sudo,系统执行的是/root/.ssh/id_rsa下的key去匹配;
不加sudo,系统执行的是/home/lh/.ssh/id_rsa下的key;
-
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,检查密钥为可用。