版權聲明:本文為博主原創文章,未經博主允許不得轉載。
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 上執行
- ssh 172.172.230.210 hostname
- 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
- vi /etc/selinux/config
- # This file controls the state of SELinux on the system.
- # SELINUX=disabled
- # enforcing - SELinux security policy is enforced.
- # permissive - SELinux prints warnings instead of enforcing.
- # disabled - No SELinux policy is loaded.
- SELINUX=disabled
- # SELINUXTYPE= can take one of these two values:
- # targeted - Targeted processes are protected,
- # mls - Multi Level Security protection.
- SELINUXTYPE=targeted
##selinux 設置為disabled
3) iptables
- service iptables status
- iptables: Firewall is not running.
##iptables服務沒有起,所以不是這個原因
3.2 查看172.172.230.210 的/var/log/secure日志
通過上面的分析我們大致可以判斷應該是目錄權限導致互信不生效了,接一下來我們查看一下/var/log/secure日志中有什么信息:
- May 17 17:17:15 shaofei-test-mysql-01 sshd[24719]: Failed password for root from 172.172.230.211 port 17890 ssh2
- May 17 17:17:17 shaofei-test-mysql-01 sshd[24719]: Failed password for root from 172.172.230.211 port 17890 ssh2
- May 17 17:17:17 shaofei-test-mysql-01 sshd[24721]: Connection closed by 172.172.230.211
- May 17 18:08:26 shaofei-test-mysql-01 sshd[25004]: Authentication refused: bad ownership or modes for directory /root
- 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