I am trying to use a python script to get an SQL dump from a remote host, with an intermediate host as proxy, like so:
local machine -> proxy -> remote
The proxy needs to be there because the remote host only allows connections through that proxy.
Note: I am aware of a similar question at How to connect to a database through a Paramiko Tunnel (or similar package) but the solution seems to be specific to PostgreSQL.
I am making the connection using SSH via paramiko. I am aware that forward.py is the paramiko example for port forwarding, but I am not sure if I am using it correctly. This is what I did (PX=proxy, RMT=remote):
forward.py --password --host=PX --port=PXport --user=PXusr RMT:RMTport
And I get this result:
*** Unable to open host keys file
*** Warning: no host key for PX
Connecting to ssh host PX:PXport ...
Now forwarding port 4000 to RMT:RMTport ...
The script then gets stuck at the last line.
Q1: Does anyone have an example of how to use paramiko's forward.py to connect to remote host via proxy?
Q2: After connection is established, is it possible to programatically execute shell commands on the remote host?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…