pahaz / sshtunnel

SSH tunnels to remote server.
MIT License
1.23k stars 184 forks source link

sshtunnel not working. keeps showing ERROR | Password is required for key #272

Open shamounilyas opened 1 year ago

shamounilyas commented 1 year ago

I have been using sshtunnel for a long time to connect to my mysql database on a linode server. Recently it stopped working. It is showing me the following error:

ERROR | Password is required for key

I use the following script to connect to the remote server.

key_file = os.path.join('C:\\Users\\user\\.ssh', 'id_rsa')

server = sshtunnel.SSHTunnelForwarder(
    ('remote_ip_address',22),
    ssh_username="user",
    ssh_pkey= key_file,
    ssh_private_key_password="password",
    remote_bind_address=('127.0.0.1', 3306),
    local_bind_address=('127.0.0.1', 3306)
)

server.start()

I can connect to the server through SSH just fine otherwise - through terminal. Just not happening through sshtunnel module.

hardyoyo commented 1 year ago

this seems to be caused by this line: https://github.com/pahaz/sshtunnel/blob/master/sshtunnel.py#L1314

which incorrectly emits an error message, when this message should be classed as a warning.

I have successfully monkey-patched this code to emit a warning, which I can then ignore, in my own code. There are multiple threads about this issue in various forums, and the general advice seems to be "just ignore it, it's not an error, your code will keep working" ... I beg to differ, it literally is an error, and that line is where it's thrown.

I mention this in the hopes that line can be changed to logger.warning ... but in the mean time, if you'd like to keep using this library as-is, you can monkey-patch the read_private_key_file function in sshtunnel.py.