user2741700
user2741700

Reputation: 901

SSH Tunnel for Python MySQLdb connection with public key

I am trying to use MySQLdb but I didn't find anywhere how to make connection throught a SSH Tunel using a public key. Anybody can please guide me throught this ?

Thank you very much.

Upvotes: 1

Views: 1387

Answers (1)

PepperoniPizza
PepperoniPizza

Reputation: 9112

As you said, you need first to create a tunnel, so in your shell do:

ssh -i ~/.ssh/keyfile.pem -L 3306:127.0.0.1:22 <hostIP>

and change your Python code to something like the following for connecting:

conn = MySQLdb.connect(host='127.0.0.1', port=3306, user='username', passwd='pass', db='DB')

Upvotes: 1

Related Questions