Skip to main content

A simple auto reconnect ssh tunnel client

Project description

autossh

Usage:

from autossh import AutoSSHTunnel  

with AutoSSHTunnel(
    ssh_server='ssh.example.com', 
    ssh_username='your_username', 
    ssh_password='your_password', 
    remote_host='remote.example.com', 
    remote_port=3306, 
    local_port=5000,
    ssh_port=2222   
) as tunnel:
    info = tunnel.get_tunnel_info()
    print(f"SSH tunnel established from local port {info['local_port']} to {info['remote_host']}:{info['remote_port']}")
    print(f"Tunnel is active: {'Yes' if info['is_active'] else 'No'}")

Or:

from autossh import AutoSSHTunnel  

tunnel = AutoSSHTunnel(
    ssh_server='ssh.example.com', 
    ssh_username='your_username', 
    ssh_password='your_password', 
    remote_host='remote.example.com', 
    remote_port=3306, 
    local_port=5000,
    ssh_port=2222  
)

tunnel.start()

try:
    info = tunnel.get_tunnel_info()
    print(f"SSH tunnel established from local port {info['local_port']} to {info['remote_host']}:{info['remote_port']}")
    print(f"Tunnel is active: {'Yes' if info['is_active'] else 'No'}")
finally:
    tunnel.stop()

Or with cli:

autossh-py your_username@ssh.example.com -L 5000:remote.example.com:3306 -p 2222

If you want to use in backend, you can specify password with sshpass and use nohup &:

Install sshpass as per: https://gist.github.com/arunoda/7790979 and:

nohup sshpass -p your_password autossh-py -p 2222 -L 5000:remote.example.com:3306 your_username@ssh.example.com &

Also support ssh key:

autossh-py -i ~/your_key -L 3306:localhost:3306 your_username@ssh.example.com

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

autossh-0.0.1.3.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

autossh-0.0.1.3-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file autossh-0.0.1.3.tar.gz.

File metadata

  • Download URL: autossh-0.0.1.3.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.19

File hashes

Hashes for autossh-0.0.1.3.tar.gz
Algorithm Hash digest
SHA256 952a39d6fab3de564f68250c3c6fb5977fd0d9582d3f56ec9e4460aa1b84ca47
MD5 9f98617683b124b6deac9c44e0004c95
BLAKE2b-256 e509d8da7510d654b3f7556922ccf06e3a1a5f3ccf3ed200d4e340f9d523b6eb

See more details on using hashes here.

File details

Details for the file autossh-0.0.1.3-py3-none-any.whl.

File metadata

  • Download URL: autossh-0.0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 4.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.19

File hashes

Hashes for autossh-0.0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 9284f60f0f1f463cc99a2bf973cce65227ed3ebe634a9c42f4e068d0369fcebf
MD5 ad59124dfc0ba7f1ef83a1e0988634f3
BLAKE2b-256 522f660cd5b8181b438abc5242c74fc685a089947ba0a44245380fcde2129db0

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page