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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM