Skip to main content

Automatically reconnect SSH sessions

Project description

PyAutoSSH

Python 3.9+ License: MIT

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.9 or newer
  • SSH client (ssh command 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

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 messages
  • ServerAliveCountMax: Number of keep-alive messages that can be lost before disconnecting
  • RequestTTY: Forces TTY allocation (required for interactive sessions)

can be configured depending on how aggressively you want to reconnect.

Tips

  1. Use key-based authentication
  2. Configure SSH agent for passwordless authentication with passphrase-protected keys
  3. Adjust keep-alive settings based on how aggressive you want to reconnect
  4. Use terminal multiplexers (e.g. tmux or screen) for session persistence

Related Projects

  • autossh - The original AutoSSH by Carson Harding

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

pyautossh-0.3.0.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyautossh-0.3.0-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

Details for the file pyautossh-0.3.0.tar.gz.

File metadata

  • Download URL: pyautossh-0.3.0.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for pyautossh-0.3.0.tar.gz
Algorithm Hash digest
SHA256 87bbdac1a80be54e76743e564978a444fb135e31846eedd76e3496d1fbdb0b95
MD5 b6c31b2335443fac14a5c50c5539df09
BLAKE2b-256 139fd8c7da8b981f02398e055d95073ca61476da05d8bb62c6891288f6955fbe

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyautossh-0.3.0.tar.gz:

Publisher: publish.yaml on chrisdeutsch/pyautossh

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyautossh-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: pyautossh-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 4.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for pyautossh-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4a3ea67574752220fbe3a6b3ce4f1419cf82926bce657053dada42003fca233b
MD5 452e914fd3703863b1ebb0ec11db3125
BLAKE2b-256 f0294850b2b2700120c7aa54dd4fdd76ddcb444318bb9437cd481d259f6c41f0

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyautossh-0.3.0-py3-none-any.whl:

Publisher: publish.yaml on chrisdeutsch/pyautossh

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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