背景
自己搭建了git服务器,想通过ssh免密登录,拉取代码
一般情况只需在.ssh/authorized_keys 中加入 需要免密机子的ssh公钥,就可以免密拉取了
自己手头处理过的服务器也有10来台了,但还是被这次的免密问题,坑了1~2天,特记录下来
通常解决思路
a) 服务器B上.ssh目录的权限必须是700
b) 服务器B上.authorized_keys文件权限必须是600或者644
本次排查
a)以前的方法都试了一遍,并和另外的服务器也进行比对,什么都一样,但就是需要密码登录
b)了解了一个命令 ssh -vvv root@ip
如 ssh -vvv root@123.45.6.78 它可以打印整个ssh登录的debug
本次问题其中有段
debug3: receive packet: type 51
debug1: Authentications that can continue: gssapi-keyex,gssapi-with-mic,password
正常的提示
debug3: receive packet: type 52
debug1: Authentication succeeded (publickey).
百度google中其他博主的错误问题是这样的(大部分人的错误都和我不一样,但他们都有publickey,没有publickey还怎么免密登录。。。)
debug3: receive packet: type 51
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
这说明,整个问题的主要原因是没有 开启publickey的登录
可是配置了这么多台服务器,一般这个publickey的登录都是开启的,我这台腾讯云的服务器为什么会没有开启。
接下来就是找配置文件中去修改配置
问题解决
终于找到相关博客的类似问题
SFTP/SSH/SCP访问设置Public Key认证(适用于centosheldebian) - 走看看
vim /etc/ssh/sshd_config
// 找到 PubkeyAuthentication
PubkeyAuthentication yes
##(原先这里果然是no,开启后问题就解决了)
重启 service sshd restart
问题解决。