【问题标题】:Paramiko: password + sms-passcode autentificationParamiko:密码+短信密码认证
【发布时间】:2017-02-16 02:13:16
【问题描述】:

我需要使用 Python 中的 ssh 连接到服务器。 通常我使用Paramiko,但是这个服务器需要输入密码后通过短信发送的密码:

C:\>ssh user@hostname.com
AD Password: <password>
Enter PASSCODE: <sms passcode>

是否可以通过 Paramiko / Python 实现

【问题讨论】:

  • 你指的是键盘交互吗?
  • 我是这么认为的,因为在输入密码之前没有发送短信密码

标签: python-3.x ssh paramiko


【解决方案1】:

我不知道这是否是正确的做法,但在我的情况下似乎可行:

def interactive_auth_handler(title, instructions, prompt_list):
    if prompt_list:
        if prompt_list[0][0]=="AD Password: ":
            return [password]
        return [getpass.getpass(prompt_list[0][0])]
    return []


client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
try:
    client.connect(host, port, username=username, password=password, pkey=None)
except paramiko.ssh_exception.SSHException as e:
    transport = client.get_transport()
    transport.auth_interactive(username, interactive_auth_handler)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-09-18
    • 2015-04-03
    • 2023-02-23
    • 1970-01-01
    • 2017-07-26
    • 1970-01-01
    • 1970-01-01
    • 2013-11-06
    相关资源
    最近更新 更多