title: SSH keys forwarding via Python sshtunnel
body: <p>The question is similar to <a href="https://stackoverflow.com/questions/23666600/ssh-key-forwarding-using-python-paramiko">this one</a>, but uses <code>sshtunnel</code> library instead of directly calling <code>paramariko</code>.</p>
  
  <p>Basically, I want to programmatically repeat scenario described <a href="http://www.unixwiz.net/techtips/ssh-agent-forwarding.html" rel="nofollow noreferrer">here</a> (in <em>Public Key Access with Agent Forwarding</em> section). The idea is that I have a backend running on <strong>server1</strong> (see aforementioned section, it has graphical scheme). This backend needs to connect <strong>server2</strong> to retrieve some data using my authentication key. </p>
  
  <p>I used to use username/password, and now switched to public keys. When I've used plain password, it was like this:</p>
  
  <pre><code>from sshtunnel import SSHTunnelForwarder
  
  APP_CONFIG = {}  # here should be connection configuration
  
  def build_ssh_tunnel_config(app_config):
      cfg = app_config
      return {
          'ssh_address_or_host': (cfg['SSH_TUNNEL_HOST'],
                                  int(cfg['SSH_TUNNEL_PORT'])),
          'ssh_password': cfg['SSH_TUNNEL_PASSWORD'],
          'ssh_username': cfg['SSH_TUNNEL_USERNAME'],
          'remote_bind_address': (cfg['SSH_TUNNEL_BIND_HOST'],
                                  int(cfg['SSH_TUNNEL_BIND_PORT']))}
  
  
  cfg = build_ssh_tunnel_config(APP_CONFIG)
  server = SSHTunnelForwarder(**cfg)
  server.start()
  # communicate with host
  </code></pre>
  
  <p>But which classes/parameters should I use to repeat the same process without explicit usage of username/password, using key forwarding instead?</p>
  
  <p>I know how to do it "manually", via terminal, i.e. key forwarding is enabled and works as expected.</p>
  
  <h3>Update</h3>
  
  <p>Here is how I do it when connecting from my <strong>homepc</strong> to <strong>server2</strong> via <strong>server1</strong>:</p>
  
  <pre><code>SSH_TUNNEL_CONFIG = {
      'ssh_address_or_host': (server1_address, server1_port),
      'remote_bind_address': (server2_address, server2_port),
      'ssh_pkey': pkey_path
      'ssh_private_key_password': os.environ.get('tunnel_password'),
      'ssh_username': username
  }
  </code></pre>
  
  <p>But I don't have a <code>pkey_path</code> file on my <strong>server1</strong> host and don't want to store my private key there. That's why key forwarding is needed.</p>
  
  <p>I am not too experienced in SSH configuration, therefore probably doing something wrong or not as simple as it could be.</p>