linux 互信不生效

1.  操作系统版本

1)操作系统

 cat /etc/issue
cat /etc/issue
CentOS release 6.6 (Final)
Kernel \r on an \m

 cat /proc/version
cat /proc/version

Linux version 2.6.32-504.el6.x86_64 (mockbuild@c6b9.bsys.dev.centos.org) (gcc version 4.4.7 20120313 (Red Hat 4.4.7-11) (GCC) ) #1 SMP Wed Oct 15 04:27:16 UTC 2014

2. 问题描述

1) 配置互信

172.172.230.210 下执行(root用户)

ssh-keygen -t rsa
ssh-copy-id -i /root/.ssh/id_rsa.pub root@172.172.230.211

172.172.230.211 下执行(root用户)

ssh-keygen -t rsa
ssh-copy-id -i /root/.ssh/id_rsa.pub root@172.172.230.210

2) 验证互信是否生效

在172.172.230.210上执行

ssh 172.172.230.211 hostname >>执行成功无需提供密码

在172.172.230.211 上执行

[html] view plain copy 在CODE上查看代码片派生到我的代码片
  1. ssh 172.172.230.210 hostname  
  2. root@172.172.230.210's password:   

##但是在172.172.230.211上执行ssh连接172.172.230.210 时提示需要密码,互信没有生效。

3. 问题分析

3.1 可能会导致互信产生问题的原因有如下三个

1) 目录权限,文件权限

##以root用户为例,root目录,.ssh目录 除了目录的属主可以具有write权限以外,属组和其他用户都不能对root目录和.ssh目录具有write权限(root用户配置互信时,秘钥文件保存路径为/root/.ssh/),否则其他主机在使用互信登录该主机时,依然会提示需要输入密码。authorized_keys文件权限应该为600

2) seliux

[html] view plain copy 在CODE上查看代码片派生到我的代码片
  1. vi /etc/selinux/config   
  2.   
  3. # This file controls the state of SELinux on the system.  
  4. SELINUX=disabled  
  5. #     enforcing - SELinux security policy is enforced.  
  6. #     permissive - SELinux prints warnings instead of enforcing.  
  7. #     disabled - No SELinux policy is loaded.  
  8. SELINUX=disabled  
  9. SELINUXTYPE= can take one of these two values:  
  10. #     targeted - Targeted processes are protected,  
  11. #     mls - Multi Level Security protection.  
  12. SELINUXTYPE=targeted  

##selinux 设置为disabled

3) iptables

[html] view plain copy 在CODE上查看代码片派生到我的代码片
  1. service iptables status  
  2. iptables: Firewall is not running.  

##iptables服务没有起,所以不是这个原因

3.2 查看172.172.230.210 的/var/log/secure日志

  通过上面的分析我们大致可以判断应该是目录权限导致互信不生效了,接一下来我们查看一下/var/log/secure日志中有什么信息:

 

[html] view plain copy 在CODE上查看代码片派生到我的代码片
  1. May 17 17:17:15 shaofei-test-mysql-01 sshd[24719]: Failed password for root from 172.172.230.211 port 17890 ssh2  
  2. May 17 17:17:17 shaofei-test-mysql-01 sshd[24719]: Failed password for root from 172.172.230.211 port 17890 ssh2  
  3. May 17 17:17:17 shaofei-test-mysql-01 sshd[24721]: Connection closed by 172.172.230.211  
  4. May 17 18:08:26 shaofei-test-mysql-01 sshd[25004]: Authentication refused: bad ownership or modes for directory /root  
  5. May 17 18:08:26 shaofei-test-mysql-01 sshd[25004]: Authentication refused: bad ownership or modes for directory /root  

##日志中很清楚的反应了因为/root目录权限的问题,导致互信失败。后来发现172.172.230.210 上的/root 目录的权限为777,修改为700或者750问题解决

  注意172.172.230.210上目录权限有问题会导致其他主机在使用免密码登录该服务器的时候又问题,但是如果其他机器的目录和文件权限没有问题,并且配置了互信,那么172.172.230.210使用免密码登录其他服务器是不会有问题的

4. 解决方案

   修改/root目录权限为 700 或者750,或者755

 

http://blog.csdn.net/shaochenshuo/article/details/51438354

转载于:https://www.cnblogs.com/seasonzone/p/6097987.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值