当前位置: 移动技术网 > 科技>操作系统>Linux > 解决linux下set_loginuid failed opening loginuid报错问题

解决linux下set_loginuid failed opening loginuid报错问题

2018年07月07日  | 移动技术网科技  | 我要评论

 自从使用php-syslog-ng监控日志信息后,经常发现一些过去会忽略的报错信息,目前正逐一解决中。其中一个报错发生在,我使用密钥通过ssh登陆到服务器的时候,日志信息显示:

nov 19 10:32:20 printserver auth 10:32:20 pam_loginuid[9691]: set_loginuid failed opening loginuid
nov 19 10:32:20 printserver auth 10:32:20 remote(pam_unix)[9691]: session opened for user root by (uid=0)
nov 19 10:32:20 printserver auth 10:32:20 sshd[9689]: accepted publickey for root from 192.168.228.244 port
1487 ssh2

一、原因
操作系统:红旗dc server 5.0
分析以前的系统日志,并没有发现类似的报错信息,故怀疑是最近的操作导致的。
从两方面分析:

1、openssh-server从4.0p1升级到4.7p1;
2、使用密钥登陆代替原来的密码登陆方式。

先尝试用原来的密码方式登陆,没有报错;再对比其他机器上原4.0p1版的状态,使用密钥登陆,也没有报错。由于我升级openssh-server的时候,使用它自带的默认配置文件而非系统4.0p1版的配置,故觉得报错,和配置及使用密钥登陆都有关。

二、解决
经查找资料后测试,可通过修改openssh-server的配置文件解决问题。
修改/etc/ssh/sshd_config为:


#challengeresponseauthentication yes
challengeresponseauthentication no  #关闭挑战应答方式
usepam no  #不使用pam认证

保存后,重启sshd服务即可。

三、说明
上述两个参数的说明,可从帮助文档得到注解:


# set this to 'yes' to enable pam authentication, account processing,
# and session processing. if this is enabled, pam authentication will
# be allowed through the challengeresponseauthentication and
# passwordauthentication.  depending on your pam configuration,
# pam authentication via challengeresponseauthentication may bypass
# the setting of "permitrootlogin without-password".
# if you just want the pam account and session checks to run without
# pam authentication, then enable this but set passwordauthentication
# and challengeresponseauthentication to 'no'.

简单来讲,就是如果打开usepam,则会根据challengeresponseauthentication来决定是否使用挑战应答方式(我不知道是否这样翻译)。而该方式是根据密码判断的,不能和密钥登陆兼容,所以会出现报错。
不同的配置,可从日志中得到完全不同的结果:
1、关闭challengeresponseauthentication和打开usepam
使用密钥登陆:

引用
nov 19 10:57:20 printserver auth 10:57:20 sshd(pam_unix)[10322]: session opened for user root by root(uid=0)
nov 19 10:57:20 printserver auth 10:57:20 sshd[10320]: accepted publickey for root from 192.168.228.244 port 1595 ssh2

2、打开challengeresponseauthentication和usepam
使用密钥登陆就会报错,而使用密码登陆是正常的:

nov 19 12:23:33 printserver sshd(pam_unix)[24454]: session opened for user root by root(uid=0)

四、其他
在google的时候,发现有另外一种解决方法:点击
就是修改/etc/pam.d/sshd,把下面这行注释:

session required pam_loginuid.so

不过,我在系统中并没有找到这行。反而,从日志可以看到,报错是由pam调用remote发出的,所以,我修改/etc/pam.d/remote,把这行注释:

引用
session    required     pam_loginuid.so

这样,确认不会再报上面的错误。但登陆的时候,日志就会显示:

nov 19 10:06:31 printserver sshd[9582]: accepted publickey for root from 192.168.228.244
port 1228 ssh2
nov 19 10:06:31 printserver remote(pam_unix)[9584]: session opened for user root by (uid=0)
nov 19 10:06:31 login -- root[9584]: root login on pts/2 from 192.168.228.244

发出信息的主机从printserver改为login了,日志分类会有有错,不利于使用咯。
◎至于因为核心没有打开config_audit功能引起的解决办法
经确认,红旗dc server 5.0的核心是已经打开config_audit的,所以,解决方法无效。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网