SSH tunnel from Python is too slow to connect
Question: I'm connecting to a remote SQL database over SSH. If I set up the SSH
connection from the Linux command line (using `ssh-add my_private_key.key` and
then `ssh user@mysite.co.uk`), it takes less than a second to connect. But if
I do it from Python using [sshtunnel](https://github.com/pahaz/sshtunnel) (in
the following script), it takes around 70 seconds. I accept that using Python
might be a bit of an overhead, but not that much! And especially since, if I
run the Python script _after_ having connected from the command line, it's
very fast. What do I need to add in the script to make it faster?

Python script:

    
    
    import pymysql, shlex, shutil, subprocess
    import logging
    import sshtunnel
    from sshtunnel import SSHTunnelForwarder
    import iot_config as cfg
    
    def OpenRemoteDB():
        global remotecur, remotedb
        sshtunnel.DEFAULT_LOGLEVEL = logging.DEBUG
        with SSHTunnelForwarder(
                (cfg.sshconn['host'], cfg.sshconn['port']),
                ssh_username = cfg.sshconn['user'],
                ssh_private_key = cfg.sshconn['private_key_loc'],
                ssh_private_key_password = cfg.sshconn['private_key_passwd'],
                remote_bind_address = ('127.0.0.1', 3306)) as server:
            print("OK")
    
    # Main program starts here
    OpenRemoteDB()
    

Python output:

    
    
    2016-09-20 12:34:15,272 | WARNING | Could not read SSH configuration file: ~/.ssh/config
    2016-09-20 12:34:15,305 | INFO    | 0 keys loaded from agent
    2016-09-20 12:34:15,332 | DEBUG   | Private key file (/etc/ssh/my_private_key.key, <class 'paramiko.rsakey.RSAKey'>) successfully loaded
    2016-09-20 12:34:15,364 | INFO    | Connecting to gateway: mysite.co.uk:22 as user 'user'
    2016-09-20 12:34:15,389 | DEBUG   | Concurrent connections allowed: True
    2016-09-20 12:34:15,409 | DEBUG   | Trying to log in with key: b'XXX'
    2016-09-20 12:35:26,610 | INFO    | Opening tunnel: 0.0.0.0:34504 <> 127.0.0.1:3306
    


Answer: Doh! After posting this question I thought it would be a good idea to make
sure sshtunnel was up-to-date - and it wasn't. So I've updated from 0.0.8.1 to
the latest version (0.1.0) and my problem is solved!

