ssh错误情况总结

问题一:github私钥验证失败

问题描述

​ 配置好ssh私钥与公钥后,仍然无法使用ssh -T [email protected] 指令成功访问github

原因

​ 参考:https://stackoverflow.com/questions/57734669/gitgithub-com-permission-denied-publickey
​ 参考:How to run ssh-add on windows? - Stack Overflow

1
2
3
4
5
6
7
8
# 执行ssh -vT [email protected] 命令
ssh -vT [email protected]
# 返回结果中发现debug信息中值尝试了默认名的私钥文件
debug1: Will attempt key: C:\\Users\\WilsonPC/.ssh/id_rsa
debug1: Will attempt key: C:\\Users\\WilsonPC/.ssh/id_dsa
debug1: Will attempt key: C:\\Users\\WilsonPC/.ssh/id_ecdsa
debug1: Will attempt key: C:\\Users\\WilsonPC/.ssh/id_ed25519
debug1: Will attempt key: C:\\Users\\WilsonPC/.ssh/id_xmss

​ 可以看出,使用诸如OpenSSH等的ssh-agent帮助下,可以在本机注册不同名称的私钥,否则就只能选择诸如id_rsa等默认名称的私钥

解决方案

​ 方案一:将私钥名改回id_rsa即可
​ 方案二:通过ssh-add将私钥添加至ssh-agent缓存中即可(需要启动ssh-agent服务)

问题二:无法使用ssh-add命令

问题描述

​ Ubuntu上添加私钥时提示如下:

1
2
3
4
# 输入
ssh-add id_rsa_wilsonUbuntu-Git
# 显示
Could not open a connection to your authentication agent

原因:

​ 需要先执行一次ssh-agent bash激活ssh-agent,然后才能使用ssh-add添加私钥文件

问题三:ssh-add添加私钥失败

问题描述

​ 添加私钥时提示:

1
2
3
4
# 输入
ssh-add id_rsa_wilsonUbuntu-Git
# 显示
WARNING: UNPROTECTED PRIVATE KEY FILE!

原因

​ 添加的私钥文件权限不正确。参考:It is required that your private key files are NOT accessible by others_IBLiplus的博客-CSDN博客

解决方案

​ 给私钥600权限

1
chmod 600 id_rsa_wilsonUbuntu-Git