A command-line SSH tunnel manager written in Go that lets you define, open and close port forwards from a TOML config.
pahaz/sshtunnel
Python library and CLI for opening SSH tunnels that forward local ports to services on remote or private hosts via paramiko.
- Stars
- 1,305
- Forks
- 200
- Open issues
- 71
- Last commit
- 2 days ago
What is it?
sshtunnel lets Python code and the command line set up SSH port forwarding. It is useful when a service such as a web app or database is only reachable through an SSH port, or when a private server sits behind a gateway that exposes only SSH.
The main entry point is SSHTunnelForwarder, which can be used with start()/stop() or as a context manager via open_tunnel. Once started, the tunnel exposes a local_bind_port that the application connects to. Authentication supports passwords, private key files with optional passphrases, and keys from an SSH agent or ~/.ssh/config. Multi-hop tunnels can be chained by pointing one tunnel at the local port of another.
The project also ships a sshtunnel CLI, which takes SSH credentials, remote bind addresses and local bind addresses as arguments. It is pure Python and runs on Windows as well as Unix-like systems.
Key features
- 01Forward local ports to remote services reachable only over SSH.
- 02Start and stop tunnels programmatically or with a with-statement.
- 03Support password, private key and SSH agent authentication.
- 04Chain multiple tunnels to reach hosts behind a gateway.
- 05Provide a command-line interface for quick forwarding.
- 06Read hosts and settings from ~/.ssh/config.
Use cases
- Connecting to a database or web service on a server whose only open port is SSH.
- Reaching a private host through a bastion or jump server from test scripts.
- Forwarding a local development database such as a Vagrant VM port from a script.
- Automating tunnel setup in CI or data pipelines that need remote resources.
Quick start
- 1
Install the package from PyPI
pip install sshtunnel - 2
Open a tunnel from Python using SSHTunnelForwarder and read server.local_bind_port
In collections
Topics
FAQ
- What is sshtunnel?
- Python library and CLI for opening SSH tunnels that forward local ports to services on remote or private hosts via paramiko. sshtunnel lets Python code and the command line set up SSH port forwarding. It is useful when a service such as a web app or database is only reachable through an SSH port, or when a private server sits behind a gateway that exposes only SSH.
- Is sshtunnel free to use? What license does it have?
- sshtunnel is open source under the MIT license. Check the license terms before using it in commercial products.
- Is sshtunnel still maintained?
- Actively maintained. The last commit to sshtunnel was on Nov 6, 2026.
- What can I use sshtunnel for?
- Connecting to a database or web service on a server whose only open port is SSH. Reaching a private host through a bastion or jump server from test scripts. Forwarding a local development database such as a Vagrant VM port from a script. Automating tunnel setup in CI or data pipelines that need remote resources.
- How do I install sshtunnel?
- Install the package from PyPI: pip install sshtunnel Open a tunnel from Python using SSHTunnelForwarder and read server.local_bind_port
- Where can I get sshtunnel?
- The source code and installation instructions are on GitHub: https://github.com/pahaz/sshtunnel
Summary generated by AI from the project's README. GitHub stats refresh daily.
Related projects
Python library that simplifies SSH CLI connections to multi-vendor network devices, for sending show commands and config changes.
A netcat-like CLI and Go library that connects two machines over Tailscale's WireGuard data plane without needing a Tailscale account or control plane.
A terminal TUI for browsing, connecting to, and managing SSH hosts defined in your ~/.ssh/config file.
A minimal Rust CLI that exposes a local TCP port to a remote server, so localhost services can be reached from the public internet.
A native Rust desktop workspace for databases, SSH, SFTP, terminals, remote desktop, monitoring, Markdown notes and AI agents.