【问题标题】:PAM Authentication failure for root during pexpect pythonpexpect python期间root的PAM身份验证失败
【发布时间】:2017-05-03 16:47:13
【问题描述】:

以下观察并非总是如此,但在使用 root 用户和正确密码的 ssh 多次访问 SUT 一段时间后,python 代码会遇到问题:

Apr 25 05:51:56 SUT sshd[31570]: pam_tally2(sshd:auth): user root (0) tally 83, deny 10
Apr 25 05:52:16 SUT sshd[31598]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=10.10.10.13  user=root
Apr 25 05:52:21 SUT sshd[31568]: error: PAM: Authentication failure for root from 10.10.10.13
Apr 25 05:52:21 SUT sshd[31568]: Connection closed by 10.10.10.13 [preauth]

这是下面的python代码:

COMMAND_PROMPT = '.*:~ #'
SSH_NEWKEY = '(?i)are you sure you want to continue connecting'

def scp(source, dest, password):
    cmd = 'scp ' + source + ' ' + dest
    try:
        child = pexpect.spawn('/bin/bash', ['-c', cmd], timeout=None)
        res = child.expect([pexpect.TIMEOUT, SSH_NEWKEY, COMMAND_PROMPT, '(?i)Password'])
        if res == 0:
            print('TIMEOUT Occurred.')
        if res == 1:
            child.sendline('yes')
            child.expect('(?i)Password')
            child.sendline(password)
            child.expect([pexpect.EOF], timeout=60)
        if res == 2:
            pass
        if res == 3:
            child.sendline(password)
            child.expect([pexpect.EOF], timeout=60)
    except:
        print('File not copied!!!')
        self.logger.error(str(self.child))

当 ssh 不成功时,这是预期的打印输出:

version: 2.3 ($Revision: 399 $)
command: /usr/bin/ssh
args: ['/usr/bin/ssh', 'root@100.100.100.100']
searcher: searcher_re:
    0: re.compile(".*:~ #")
buffer (last 100 chars): :
Account locked due to 757 failed logins

Password:
before (last 100 chars): :
Account locked due to 757 failed logins

Password:
after: <class 'pexpect.TIMEOUT'>
match: None
match_index: None
exitstatus: None
flag_eof: False
pid: 2284
child_fd: 5
closed: False
timeout: 30
delimiter: <class 'pexpect.EOF'>
logfile: None
logfile_read: None
logfile_send: None
maxread: 2000
ignorecase: False
searchwindowsize: None
delaybeforesend: 0
delayafterclose: 0.1
delayafterterminate: 0.1

任何线索可能是什么,是否可能在我的 SUT 上为 pam 身份验证配置了任何缺失或错误?问题是当 SUT 以这个 pam 故障启动时,python 代码总是会出现问题,只有重新启动 SUT 似乎有帮助:(

通过 ssh root@... 手动访问 SUT 始终有效,即使 pexpect 不能!该帐户似乎没有被锁定,根据:

SUT:~ # passwd -S root
root P 04/24/2017 -1 -1 -1 -1

我已经研究了一些其他问题,但没有提到真正的解决方案或可以使用我的 python 代码。

感谢您的建议。

【问题讨论】:

  • 从代码中可以看出哪些错误?执行哪些条件?
  • 其实它只是去除外!我还没有添加代码来获取错误号或损坏的条件!!!我不知道如何以一般方式做到这一点:(
  • 我已经更新了有关该问题的更多信息。
  • “帐户被锁定”是您无法登录的明显原因。
  • 是的,我同意,但帐户似乎没有被锁定!!可以看到root用户在passwd -S命令执行中没有LK标签!!!

标签: python-2.7 ssh pexpect pam


【解决方案1】:

我的工作是为了测试目的修改 pam_tally 配置文件。似乎 SUT 承认多重访问是一种威胁,甚至锁定了 root 帐户!

通过在几个 pam_tally 配置文件中删除此条目 even_deny_root root_unlock_time=5:

/etc/pam.d/common-account:account    required        pam_tally2.so     deny=10 onerr=fail unlock_time=600 even_deny_root root_unlock_time=5 file=/home/test/faillog
/etc/pam.d/common-auth:auth          required        pam_tally2.so     deny=10 onerr=fail unlock_time=600 even_deny_root root_unlock_time=5 file=/home/test/faillog

这些更改将被动态激活,无需重新启动服务!

注意:重启后这些条目很可能会恢复!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-09-28
    • 1970-01-01
    • 2015-02-17
    • 2020-03-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多