Skip to main content

SSH Tunnel Switch

CI CodeQL PyPI Python License

Lines of Code Code style: Ruff Duplicated Lines (%) Coverage

Vulnerabilities Security Rating Maintainability Rating Reliability Rating Quality Gate Status Code Smells Bugs Technical Debt

Rotate SSH SOCKS5 tunnels through a REST API or CLI. The built-in HTTP proxy forwards HTTP requests and HTTPS CONNECT traffic through the active tunnel, using SOCKS5 for remote DNS resolution.

The server runs independently and requires Python 3.12+ and OpenSSH. No OpenCode, Node.js, Bun or plugin is required.

Install and run

python3 -m venv .venv
.venv/bin/python -m pip install ssh-tunnel-switch
.venv/bin/tunnel-switch --version
.venv/bin/tunnel-switch init-config --output config.yaml

init-config is available from version 1.0.0. It creates a mode-0600 example and refuses to overwrite existing files. For 0.1.0, download the example configuration and protect it with chmod 600 config.yaml.

Edit the SSH host aliases in the YAML. Verify host keys and key/agent authentication using your normal SSH client before starting the service. SSH accounts must allow TCP forwarding. Existing ~/.ssh/config settings apply when YAML does not override them.

.venv/bin/tunnel-switch validate --config config.yaml
.venv/bin/tunnel-switch serve --config config.yaml

Startup generates and saves an API token if needed and prints it to the console. Keep the configuration and logs private. On an interactive terminal serve shows a live status panel while timestamped service and access logs are written to the log file (logging.file); when run under systemd the timestamped lines also reach the journal. By default the SOCKS5 listener is 127.0.0.1:1080, the HTTP proxy is 127.0.0.1:8118, and the REST API is 127.0.0.1:8765. The panel also carries an HTTP requests row with the requests the proxy sent over the current SSH connection and over the one before it, described under Use the proxy.

The service watches its YAML and applies configuration changes without restarting or dropping the tunnel (systemctl reload or POST /reload trigger it immediately). On an interactive terminal the status panel also responds to keys: Ctrl+R reloads the configuration, Ctrl+E connects, Ctrl+D disconnects, Alt+R restarts the current server, Ctrl+N rotates to the next, Alt+S (or Ctrl+S, which needs no Option-key setting) opens a picker over the configured servers — a pop-up over the dashboard whose window scrolls to fit the display when they do not all fit — so you can connect to a chosen one, and Ctrl+C still stops the service. The rotation cooldown still gates the API, Alt+R and Ctrl+E, but not the deliberate keys Ctrl+N and Alt+S/Ctrl+S. The panel title shows the running version, which is also reported by tunnel-switch --version, the serve startup banner and GET /status.

Use the proxy

curl --proxy http://127.0.0.1:8118 https://example.com/
.venv/bin/tunnel-switch status --config config.yaml
.venv/bin/tunnel-switch rotate --config config.yaml

Proxy-aware applications can use HTTP_PROXY and HTTPS_PROXY set to http://127.0.0.1:8118; set NO_PROXY=localhost,127.0.0.1,::1 for direct local control calls. SOCKS-aware clients can use socks5h://127.0.0.1:1080 directly. HTTPS remains encrypted end to end. Forwarding fails when SOCKS is unavailable and never falls back to a direct destination connection.

Every request the proxy carries is counted: a forwarded request and a CONNECT each count once, while a request the tunnel could not carry counts nowhere and the encrypted requests inside a CONNECT tunnel cannot be seen at all. The totals are shown in the status panel's HTTP requests row and reported by GET /status as requests.current for the current SSH connection and requests.last for the connection before it.

The bearer token protects the REST API only. HTTP and SOCKS proxy listeners are unauthenticated: retain loopback defaults or restrict access with a firewall. Protect remote REST access with TLS. See the security policy.

Guides

License

MIT.

Metadata

Release files for ssh-tunnel-switch 1.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ssh-tunnel-switch 1.5.0
File Size Uploaded Provenance Actions
ssh_tunnel_switch-1.5.0.tar.gz 129.1 kB With provenance Details for ssh_tunnel_switch-1.5.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ssh-tunnel-switch 1.5.0
File Interpreter ABI Platform Actions
ssh_tunnel_switch-1.5.0-py3-none-any.whl Python 3 none any Details for ssh_tunnel_switch-1.5.0-py3-none-any.whl

Total release size: 169.0 kB

Release files / ssh_tunnel_switch-1.5.0.tar.gz

Download URL ssh_tunnel_switch-1.5.0.tar.gz
Size 129.1 kB
Tags Source
SHA-256 checksum
How to use checksums
69486f1ce8002cfa8bfff2a90e8c1fec162e5d0a0150c6f018dbafb5c769d64b
BLAKE2b-256 checksum
How to use checksums
8acffbff3428f82927fb1e49794dc0c77ac3e3865ae2e1d200f2136b9b72fd00
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 2, 2026.

Transparency log

Release files / ssh_tunnel_switch-1.5.0-py3-none-any.whl

Download URL ssh_tunnel_switch-1.5.0-py3-none-any.whl
Size 39.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
55f5e5883e658fdb45ca33e63c2c9842523c1f82010cdab3fea40c0200c4a29b
BLAKE2b-256 checksum
How to use checksums
b0bc70868a533de5eb3d0e93bbaec1ecb2d2b1e33fb6ab5e35f578950bff6a6c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 2, 2026.

Transparency log

Security for ssh-tunnel-switch 1.5.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for ssh_tunnel_switch-1.5.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 2, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page