title: Python Paramiko (Client) Multifactor Authentication
body: <p>I'm attempting to use Paramiko (on Python 2.7) to connect to a host that uses multifactor authentication (username + password + one-time-password). The <code>transport.auth_interactive</code> function seems to be the way to do this (based on what I'm understanding from the documentation), but execution never reaches that point - the authentication fails on the <code>client.connect</code> line.</p>
  <p>I seem to be missing something.</p>
  <p>This is the code:</p>
  <pre class="lang-python prettyprint-override"><code>#!/usr/bin/env python
  
  import paramiko
  import getpass
  import os
  import logging
  
  user = &quot;&quot;
  pw = &quot;&quot;
  mfa = &quot;&quot;
  
  def inter_handler(title, instructions, prompt_list):
      resp = []
  
      for pr in prompt_list:
          if pr[0].strip() == &quot;Username:&quot;:
              resp.append(user)
          elif pr[0].strip() == &quot;Password:&quot;:
              resp.append(pw)
          elif pr[0].strip() == &quot;OTP Code:&quot;:
              resp.append(mfa)
          
      return tuple(resp)
  
  
  #Main Entry Point
  if __name__ == &quot;__main__&quot;:
  
      paramiko.util.log_to_file(os.path.expanduser('~/paramiko.log'), logging.DEBUG)
  
      user = raw_input(&quot;Username: &quot;)
      pw = getpass.getpass(&quot;Password: &quot;)
      mfa = raw_input(&quot;OTP Code:&quot;)
  
      client = paramiko.SSHClient()
      client.set_missing_host_key_policy(paramiko.AutoAddPolicy())   #Don't care about host keys
      client.connect(&quot;mfahost.example.com&quot;, port=22, username=user, password=pw, look_for_keys=False)
      client.get_transport().auth_interactive(user, inter_handler) 
  
      client.exec_command(&quot;touch ~/paramikotestfile&quot;)
  </code></pre>