美文网首页Linux Troubleshooting
pam_access fails with hostname w

pam_access fails with hostname w

作者: yangqing | 来源:发表于2023-12-11 13:35 被阅读0次

    环境

    • CentOS 7
    • sshd
    • pam

    问题

    pam_access 引用 /etc/security/access.conf 进行访问管理,不适用于主机名,但在使用 IP 地址时工作正常。

    + : testuser : mycentos7.test.com      <------- Does not work
    + : testuser : 10.10.10.10      <------- Works fine
    
    

    解决

    在 /etc/ssh/sshd_config 中设置如下

     UseDNS = yes
    
    

    重启sshd服务

    # systemctl restart sshd
    
    

    根本原因

    这是由于 /etc/ssh/sshd_config 下的“UseDNS”选项造成的。

    • 根据 man sshd_config
    UseDNS
    Specifies whether sshd(8) should look up the remote host name and check that the resolved host name for the remote IP address maps back to the very same IP address. The default is ''yes''. 
    
    

    centos 7.6 和 centos 7.7 默认情况下 UseDNS = no。 centos 7.8 默认情况下 UseDNS = yes。

    诊断步骤

    • 通过 /etc/security/access.conf 配置 IP 地址,从远程服务器 10.10.10.10 授予访问权限
    #+ : testuser : mycentos7.test.com
    + : testuser : 10.10.10.10
    # All other users should be denied to get access from all sources.
    -:ALL:ALL
    
    

    从 /var/log/secure 登录

    7 月 3 日 15:21:35 centos sshd[3863]:接受来自 10.10.10.10 端口 34825 ssh2 的 testuser 密码 7 月 3 日 15:21:35 centos sshd[3863]: pam_unix(sshd:session): 由 (uid=0) 为用户 testuser 打开会话

    • 使用主机名配置 /etc/security/access.conf 时,远程服务器 10.10.10.10 的访问被拒绝
    + : testuser : mycentos7.test.com
    #+ : testuser : 10.10.10.10
    # All other users should be denied to get access from all sources.
    -:ALL:ALL
    
    

    从 /var/log/secure 登录

    7 月 3 日 15:22:38 centos sshd[3890]: pam_access(sshd:account): 用户访问被拒绝testuser' from10.10.10.10' 7 月 3 日 15:22:38 centos sshd[3890]:来自 10.10.10.10 端口 34826 ssh2 的 testuser 密码失败 7 月 3 日 15:22:38 centos sshd[3890]:致命:PAM 帐户配置拒绝用户 testuser 的访问 [preauth]

    • 使用主机名配置 /etc/security/access.conf 并在 /etc/ssh/sshd_config 中使用 UseDNS = yes ,从远程服务器 10.10.10.10 授予访问权限
    + : testuser : mycentos7.test.com
    #+ : testuser : 10.10.10.10
    # All other users should be denied to get access from all sources.
    -:ALL:ALL
    
    

    从 /var/log/secure 登录

    7 月 3 日 15:31:45 centos sshd[3946]:接受来自 10.10.10.10 端口 31329 ssh2 的 testuser 密码 7 月 3 日 15:31:45 centos sshd[3946]: pam_unix(sshd:session): 由 (uid=0) 为用户 testuser 打开会话

    相关文章

      网友评论

        本文标题:pam_access fails with hostname w

        本文链接:https://www.haomeiwen.com/subject/vermgdtx.html