connect ( '127.0.0.1', 10022 ) # do some operations with client session client. open_tunnel ( ( 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. Listening on port 443 and that port is open in the firewall ( Fig2): import paramiko import sshtunnel with sshtunnel. stop () Example 2Įxample of a port forwarding to a private server not directly reachable,Īssuming password protected pkey authentication, remote server’s SSH service is local_bind_port ) # show assigned local port # work with `SECRET SERVICE` through `server.local_bind_port`. from sshtunnel import SSHTunnelForwarder server = SSHTunnelForwarder ( '', ssh_username = "pahaz", ssh_password = "secret", remote_bind_address = ( '127.0.0.1', 8080 ) ) server. , password authentication and randomly assigned local bind Usage examplesĪPI allows either initializing the tunnel and starting it or using a withĬontext, which will take care of starting and stopping the tunnel: Example 1Ĭode corresponding to Fig1 above follows, given remote server’s address is įig2: How to connect to PRIVATE SERVER through SSH tunnel. (from the perspective of REMOTE SERVER) not directly visible from the If allowed by the SSH server, it is also possible to reach a private server įig1: How to connect to a service blocked by a firewall through SSH tunnel. Where only SSH port (usually port 22) is reachable. User may need to connect a port of a remote server (i.e. One of the typical scenarios where sshtunnel is helpful is depicted in theįigure below. Tox and run: python setup.py test Usage scenarios Repo and run: python setup.py install Testing the package To have it installed in your environment. Or conda install -c conda-forge sshtunnel Sshtunnel is on PyPI, so simply run: pip install sshtunnel
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |