How to create a ssh tunnel using python and paramiko?

Ivan picture Ivan · Nov 17, 2011 · Viewed 56.5k times · Source

I'm learning python. I need to tunnel creators to read information from a database and close the tunnel. I use paramiko but I have not worked with tonelem example. please give an example of a simple code creates a tunnel.

Thanks in advance!

Answer

dario picture dario · Nov 17, 2011

At work we usually create ssh tunnels forwarding ports. The way we do that is, by using the standard command ssh -L port:addr:port addr with subprocess running in a separate thread. I found this useful link: https://github.com/paramiko/paramiko/blob/master/demos/forward.py with an example of doing port forwarding with paramiko.