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 &
Project details
Release history Release notifications | RSS feed
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.2.tar.gz
(3.9 kB
view hashes)
Built Distribution
Close
Hashes for autossh-0.0.1.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fb98eea397283bbb885bd19becb5173163c401e1b7995299a85df7eaf3e6b5ff |
|
MD5 | e29afbd8e21c1462423002fc817579e9 |
|
BLAKE2b-256 | cabfa07348e42c2f40ac579b288e0e956726b50d6f3889bd4c9f9eb040369ea7 |