With the usual linux tools I make a tunnel like this:

ssh -R 22:localhost:5551 login@IP 

Everything works with a bang. Now I want to do the same, but from under the python.

Can you explain an example:

 import paramiko from sshtunnel import SSHTunnelForwarder with SSHTunnelForwarder( (REMOTE_SERVER_IP, 443), ssh_username="", ssh_pkey="/var/ssh/rsa_key", ssh_private_key_password="secret", remote_bind_address=(PRIVATE_SERVER_IP, 22), local_bind_address=('0.0.0.0', 10022) ) as tunnel: client = paramiko.SSHClient() client.load_system_host_keys() client.set_missing_host_key_policy(paramko.AutoAddPolicy()) client.connect('127.0.0.1', 10022) # do some operations with client session client.close() print('FINISH!') 

and whether the public key will be copied in this way (as for example it could be ssh-copy-id means)

  • one
    Examples do not correspond to each other. None of the examples copy public keys by themselves. Is there any motivation to build a paramiko tunnel instead of running an external command: ssh -R , which works for you? - jfs
  • agree with @jfs - don't bother, make Popen ("ssh -R 22: localhost: 5551 login @ IP") and you will be happy - rusnasonov

0