SSHTunnel searching for default private key (id_rsa) instead of the ssh_pkey I specify

Viewed 326

I am using MacOS and something in my system config keeps telling python's SSHTunnelForwarder to use my default id_rsa file INSTEAD of the file I specify in the configuration below:

>>> from sshtunnel import SSHTunnelForwarder
>>> db_tunnel = SSHTunnelForwarder(
...     ssh_host="localhost",
...     ssh_username="username",
...     ssh_port=1111,
...     ssh_pkey="~/.ssh/test",
...     remote_bind_address=("my-remote-database-domain", 3306)
... )

Gives me this error message: 2022-03-23 13:15:35,715| ERROR | Password is required for key /Users/me/.ssh/id_rsa

Where can I edit the config to override this search for the wrong key?

My ~/.ssh/config:

Host *
  AddKeysToAgent yes
  UseKeychain yes
  IdentityFile ~/.ssh/id_rsa
  IdentityFile ~/.ssh/test

And yes, I have run ssh-add ~/.ssh/test to add this key.

What else could be confusing it?

1 Answers

This error message doesn't matter if you have assigned other keys to create the connection, you can insert more logs to confirm that your program has continued to run.

And make sure the host in your MySQL connect parameter must be 127.0.0.1 :

db = pymysql.connect(host="127.0.0.1",
                             user=user,
                             password=password,
                             database='db', port= db_tunnel.local_bind_port)
Related