我有一个CentOS 7服务器。 我已经设置/root/.ssh/authorized_keys在我试图login到主机没有密码。 (是的,允许远程root访问是一个坏主意,但这是一个内部服务器。)ssh失败,在selinux审计日志中有这个。
type=USER_LOGIN msg=audit(1494544798.597:481313): pid=18660 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:sshd_t:s0-s0:c0.c1023 msg='op=login acct="root" exe="/usr/sbin/sshd" hostname=? addr=xx.xx.xx.xx terminal=ssh res=failed'
这里是.ssh的东西的权限和上下文:
# ls -aZ /root/.ssh drwx------. root root system_u:object_r:ssh_home_t:s0 . dr-xr-x---. root root system_u:object_r:admin_home_t:s0 .. -rw-------. root root system_u:object_r:ssh_home_t:s0 authorized_keys -rw-r--r--. root root unconfined_u:object_r:ssh_home_t:s0 known_hosts
我已经将权限和上下文与另一个系统的权限和上下文进行了比较,该系统允许sshlogin而不需要密码,它们是相同的。
在审计消息中没有selinux关心的文件,只是“res = fail”。
在工作日志条目的系统中有这个:
subj=system_u:system_r:sshd_t:s0-s0:c0.c1023
所以,我很困惑。 /root/.ssh中没有包含上下文system_u的文件:system_r:sshd_t。 所以,我不明白为什么这个上下文被logging下来。
有没有办法知道所有.ssh相关文件的内容应该是什么? 是的,我玩过restorecon,没有运气。
您快速跳到SELinux ….你确定你有/ etc / ssh / sshd_config正确设置,以允许通过SSH的根访问? 如果您对configuration文件进行了任何更改,是否重新启动了sshd服务?
你有没有尝试设置SELinux宽容和testing这个。
你知道,如果SELinux拒绝访问,我希望在/var/log/audit/audit.log中看到某种types的AVC(Access Vector Cache)错误。 请记住,audit.log不仅仅用于SELinux问题。 因此,你所得到的仅仅是一个失败的login报告,而不是一个SELinux错误。
你是否确定public / private openssh密钥对实际上是在ssh上下文中工作的。 您可以使用-v选项使用ssh命令来尝试日志logging以进行debugging并查看。
我也会检查/ var / log / messages和/ var / log / secure文件以获取更多信息。
这个问题有一个简短的文章 。 它说
可能是因为SELinux上下文没有正确设置在.ssh文件夹和授权密钥文件[…]解决这个问题的方法是运行
# restorecon -R -v /root/.ssh
文章还展示了如何从一开始就正确设置权限:
# chmod 755 /root/.ssh/ # chmod 600 /root/.ssh/authorized_keys # restorecon -R -v /root/.ssh
虽然我不同意在我的VPS上的第一个命令的文章
# chmod 700 /root/.ssh/
从我个人的经验来看,我学到了一些关于ssh-keyauthentication的重要事情。
PubkeyAcceptedKeyTypes=+ssh-dss到/etc/ssh/sshd_config ,并在客户机上添加~/.ssh/config 。 -vvvvv到ssh调用ssh -vvvvvv [email protected] /etc/ssh/sshd_config来完成 SyslogFacility AUTH
LogLevel DEBUG
(关于选项的帮助可以通过# man sshd_config获得)
然后在ssh连接期间看/var/log/debug 。 如果找不到debugging日志,请查看/var/log/messages和/var/log/secure (作为最后的手段,请参阅/etc/syslog.conf设置)。