Automatically reconnect SSH sessions
Project description
PyAutoSSH
A Python tool that automatically reconnects SSH sessions after connection
interruptions. Perfect for maintaining persistent connections when using
terminal multiplexers like screen or tmux on remote hosts.
Features
- Automatic reconnection on connection loss
- Compatible with existing SSH configurations
- Minimal dependencies
Prerequisites
- Python 3.10 or newer
- SSH client (
sshcommand available in PATH) - Configured SSH key-based authentication (recommended)
Installation
# Via pip (or pipx / uvx)
pip install pyautossh
# From source
git clone https://github.com/chrisdeutsch/pyautossh
cd pyautossh
pip install .
Usage
Basic Usage
pyautossh <args forwarded to ssh>
# For example
pyautossh -t user@hostname tmux new -A -s session_name
PyAutoSSH Options
PyAutoSSH accepts several specific options that control its behavior:
# Set maximum connection attempts before giving up
pyautossh --autossh-max-connection-attempts 10 user@hostname
# Set delay between reconnection attempts (in seconds)
pyautossh --autossh-reconnect-delay 5 user@hostname
# Enable verbose logging for debugging
pyautossh --autossh-verbose user@hostname
These options must be specified before any SSH arguments. All other arguments are passed directly to the SSH client.
Advanced Configuration
Create an SSH config entry in ~/.ssh/config:
Host hostname-tmux
User username
HostName hostname
RequestTTY yes
RemoteCommand tmux new-session -A -s base
ServerAliveInterval 5
ServerAliveCountMax 1
Then simply connect using:
pyautossh hostname-tmux
The parameters
ServerAliveInterval: Time interval (in seconds) for sending keep-alive messagesServerAliveCountMax: Number of keep-alive messages that can be lost before disconnectingRequestTTY: Forces TTY allocation (required for interactive sessions)
can be configured depending on how aggressively you want to reconnect.
Tips
- Use key-based authentication
- Configure SSH agent for passwordless authentication with passphrase-protected keys
- Adjust keep-alive settings based on how aggressive you want to reconnect
- Use terminal multiplexers (e.g.
tmuxorscreen) for session persistence
Related Projects
- autossh - The original AutoSSH by Carson Harding
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyautossh-0.3.1.tar.gz.
File metadata
- Download URL: pyautossh-0.3.1.tar.gz
- Upload date:
- Size: 5.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a45b20c69170ff181cace03e6d6070f86a8300480f1add342519b4c27d858a13
|
|
| MD5 |
a44b36b7aa3f001d965d27ecad578fdf
|
|
| BLAKE2b-256 |
aa37fa47629f8d56f02d021a7dcc12b4a9d6ec4798400aa65e27eae254993e5f
|
Provenance
The following attestation bundles were made for pyautossh-0.3.1.tar.gz:
Publisher:
publish.yaml on chrisdeutsch/pyautossh
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyautossh-0.3.1.tar.gz -
Subject digest:
a45b20c69170ff181cace03e6d6070f86a8300480f1add342519b4c27d858a13 - Sigstore transparency entry: 219510435
- Sigstore integration time:
-
Permalink:
chrisdeutsch/pyautossh@db83dabb92b24ff8bb1f3e7696ba31694c41f15c -
Branch / Tag:
refs/tags/v0.3.1 - Owner: https://github.com/chrisdeutsch
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@db83dabb92b24ff8bb1f3e7696ba31694c41f15c -
Trigger Event:
release
-
Statement type:
File details
Details for the file pyautossh-0.3.1-py3-none-any.whl.
File metadata
- Download URL: pyautossh-0.3.1-py3-none-any.whl
- Upload date:
- Size: 5.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
94272d8ede269e876dca1e8c4d4dd312f1aebaa8569c14e2f7950df82b3734e1
|
|
| MD5 |
90ca874023d3d3588e7b424793e9ddf2
|
|
| BLAKE2b-256 |
e9c1c53e35bbb1f11ad532f2a3b64b35ab08a56b80fb7515b61535a7cc1ec255
|
Provenance
The following attestation bundles were made for pyautossh-0.3.1-py3-none-any.whl:
Publisher:
publish.yaml on chrisdeutsch/pyautossh
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyautossh-0.3.1-py3-none-any.whl -
Subject digest:
94272d8ede269e876dca1e8c4d4dd312f1aebaa8569c14e2f7950df82b3734e1 - Sigstore transparency entry: 219510437
- Sigstore integration time:
-
Permalink:
chrisdeutsch/pyautossh@db83dabb92b24ff8bb1f3e7696ba31694c41f15c -
Branch / Tag:
refs/tags/v0.3.1 - Owner: https://github.com/chrisdeutsch
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@db83dabb92b24ff8bb1f3e7696ba31694c41f15c -
Trigger Event:
release
-
Statement type: