ssh配置互信时错误解决方法

之前项目中遇到有关配置ssh互信免密登录问题,为避免以后踩坑,现记录一下避坑指南。

1、提示如下错误:
Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
问题分析:可能是ssh配置问题。
查看日志/var/log/secure,分析问题在何处;也可以检查/var/log/messages
tail -n 20 /var/log/secure
问题处理:修改ssh配置
这里简单总结几个必须要修改的配置:

HostKey /etc/ssh/ssh_host_rsa_key
RSAAuthentication yes
PubkeyAuthentication yes #这两项为打开公钥模式
AuthorizedKeysFile .ssh/authorized_keys #配置公钥记录文件
PasswordAuthentication yes #打开密码验证模式
PermitRootLogin yes

# 查看配置
egrep "PubkeyAuthentication" /etc/ssh/sshd_config
egrep "PasswordAuthentication" /etc/ssh/sshd_config
egrep "RSAAuthentication" /etc/ssh/sshd_config
egrep "AuthorizedKeysFile" /etc/ssh/sshd_config
egrep "PermitRootLogin" /etc/ssh/sshd_config
systemctl restart sshd

2、tail -f /var/log/secure查看到日志中报如下错误:
(1)Authentication refused: bad ownership or modes for directory /root
问题分析:提示/root目录权限问题
解决方法:
chmod 755 /root

chown root.root /root

(2)Authentication refused: bad ownership or modes for file /home/git/.ssh/authorized_keys
问题分析:ssh目录和文件权限问题
解决方法:推荐权限如下

.ssh 700 
authorized_keys 600 
id_rsa 600 
id_rsa.pub 644
known_hosts 644

ssh-add id_rsa
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys

3、发现问题的所在:Authentication refused: bad ownership or modes for file
问题分析:从字面上可以看出是目录的属主和权限配置不当,查找资料得知,SSH不希望home目录和~/.ssh目录对组有写权限
解决方法:通过下面几条命令改下

chmod g-w /home/user
chmod 700 /home/user/.ssh
chmod 600 /home/user/.ssh/authorized_keys
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值