How can I ssh into a server that requires two password authentication using Python's Paramiko module?

前端 未结 1 1182
走了就别回头了
走了就别回头了 2020-12-20 02:18

How do I ssh to a server that requires dual password authentication using Paramiko?

When using a particular user, it first prompts for the user password and then fo

相关标签:
1条回答
  • 2020-12-20 02:20

    Your server uses a standard password authentication for the first password.

    The second password is asked only once shell is starting. Simple I/O is used for that.

    Additionally, your server does not seem to support "exec" interface/channel to execute commands (as ssh user@host command does not work). What is probably related to the "shell password" feature. So you probably have to use "shell" channel to execute your command, what is otherwise not recommended.

    ssh = paramiko.SSHClient()
    ssh.connect(hostname, username = username, password = password1)
    channel = ssh.invoke_shell()
    channel.send(password2 + "\n")
    channel.send(command + "\n")
    while not channel.recv_ready():
        time.sleep(1)
    out = channel.recv(9999)
    
    0 讨论(0)
提交回复
热议问题