SSH connection reuse through a temporary localhost SSH endpoint.
Project description
SSH connection reuse through a temporary localhost SSH endpoint.
It opens one upstream SSH connection to a remote host, exposes a local SSH server on 127.0.0.1:<port>, and lets you keep using standard tools like ssh, sftp, scp, ssh -L, and ssh -R against that local endpoint.
The goal is simple: verify once, authenticate once, reuse everywhere.
Installation
pip install sshshim
Usage
sshshim is a lightweight foreground tool. It keeps one real upstream SSH connection alive, reconnects automatically after transient network drops, and replays requested remote forwards after reconnect.
Why use it
SSH workflows often reconnect more than necessary:
sshfor an interactive shellsftporscpfor file transferssh -Lfor local port forwardingssh -Rfor reverse port forwarding
Even when all of those target the same machine, they often trigger separate connection setup, repeated authentication, and repeated host verification prompts. sshshim changes the workflow: instead of treating SSH as command-first, it treats it as connection-first.
Basic idea
- Start
sshshimonce. - It connects upstream to the real remote SSH server.
- It serves a temporary localhost SSH endpoint.
- Use your existing SSH tools against localhost.
Generate a localhost host key
First, generate a dedicated localhost host key for the shim if you do not already have one.
Ed25519:
ssh-keygen -t ed25519 -N ''
RSA:
ssh-keygen -t rsa -b 4096 -N ''
If you save the key at the default OpenSSH locations ~/.ssh/id_ed25519 or ~/.ssh/id_rsa, sshshim will look there automatically.
Start the shim
Using an Ed25519 key for the upstream remote host:
python sshshim.py \
--host prod.example.com \
--port 22 \
--username ubuntu \
--ed25519-key /path/to/your/remote_server_ed25519 \
--local-port 2222
If the localhost shim host key is stored somewhere else, pass it explicitly:
python sshshim.py \
--host prod.example.com \
--port 22 \
--username ubuntu \
--ed25519-key /path/to/your/remote_server_ed25519 \
--local-port 2222 \
--local-ed25519-key /path/to/your/local_shim_ed25519
You can also authenticate upstream with a password:
python sshshim.py \
--host prod.example.com \
--port 22 \
--username ubuntu \
--password your-password \
--local-port 2222
Or with an RSA private key:
python sshshim.py \
--host prod.example.com \
--port 22 \
--username ubuntu \
--rsa-key /path/to/your/remote_server_rsa \
--local-port 2222
Use your normal SSH tools against localhost
Interactive shell:
ssh -p 2222 anything@127.0.0.1
SFTP:
sftp -P 2222 anything@127.0.0.1
SCP:
scp -P 2222 file.txt anything@127.0.0.1:/tmp/
Local forwarding:
ssh -p 2222 -L 15432:localhost:5432 anything@127.0.0.1
Reverse forwarding:
ssh -p 2222 -R 18080:localhost:8080 anything@127.0.0.1
What the prototype does
- opens one upstream SSH connection
- exposes one temporary localhost SSH endpoint
- supports interactive shell sessions
- supports remote command execution
- supports
sftp/scp-style file transfer through standard SSH clients - supports
ssh -Llocal forwarding - supports
ssh -Rremote forwarding - reconnects automatically after transient upstream failures
- replays requested remote forwards after reconnect
Command-line interface
sshshim.py accepts:
--host--port--username- exactly one of:
--password--rsa-key--ed25519-key
--local-port- optionally:
--local-rsa-key--local-ed25519-key
Quick smoke-check workflow
In one terminal, start the shim:
python sshshim.py \
--host prod.example.com \
--port 22 \
--username ubuntu \
--ed25519-key /path/to/your/remote_server_ed25519 \
--local-port 2222
In another terminal, verify that standard tools reuse the local endpoint:
ssh -p 2222 anything@127.0.0.1 uname -a
sftp -P 2222 anything@127.0.0.1
ssh -p 2222 -L 15432:localhost:5432 anything@127.0.0.1
ssh -p 2222 -R 18080:localhost:8080 anything@127.0.0.1
Conceptually, this is tmux-like multiplexing for SSH capabilities, but exposed through standard SSH clients instead of a new portal, daemon, or browser UI.
Motivation
Modern work is mobile and distributed: cloud VMs, laptops, and edge devices. SSH is the universal way to reach them, but even with a single remote relationship, it often still requires too many separate SSH connections. Shell access, file transfer, and port forwarding may all target the same machine, yet in practice, they often trigger separate setups, separate authentication, and separate friction.
Common pain points include:
- reconnecting for
ssh,scp,sftp, and forwarding workflows - repeated host verification and password prompts
- brittle private key permission requirements
Some existing solutions improve parts of the experience, but still miss the mark for a lightweight local-first workflow:
- OpenSSH multiplexing helps reuse connections, but the UX is still fragmented across commands and flags
- Apache Guacamole offers a polished browser-based experience, but it is much heavier than a simple local tool
- Teleport appears closer to an infrastructure platform or control plane than a minimal localhost SSH helper
If improving SSH requires deploying a web app, a daemon, a proxy, or a gateway, that already adds friction for many users.
The motivation behind sshshim is a simpler model: SSH should be connection-first, not command-first. A user should be able to:
- Verify a host once
- Authenticate once
- Reuse that connection everywhere
That is why sshshim is designed as a small foreground program with a single abstraction: a trusted upstream SSH connection exposed as a temporary localhost SSH endpoint that standard tools can reuse immediately.
Contributing
Contributions are welcome! Please submit pull requests or open issues on the GitHub repository.
License
This project is licensed under the MIT License.
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 sshshim-0.1.0a0.tar.gz.
File metadata
- Download URL: sshshim-0.1.0a0.tar.gz
- Upload date:
- Size: 12.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2f05de21cf888d0c594b8ad8557b57fbd65dadaa7aa3de709d57146e4fcd91da
|
|
| MD5 |
b493edb4596bdcf1fc4bd803b3058e9e
|
|
| BLAKE2b-256 |
6063005dcf62f4630bb20e296271828ba118b6f8f2515217f5a198f275132a57
|
File details
Details for the file sshshim-0.1.0a0-py2.py3-none-any.whl.
File metadata
- Download URL: sshshim-0.1.0a0-py2.py3-none-any.whl
- Upload date:
- Size: 12.1 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d4e493245d0047c7e5e81338dc9c27b893a271bcfbf046ae35eebaedf310e168
|
|
| MD5 |
dc1490644ce5a2f72f2b1f7ca00c2e08
|
|
| BLAKE2b-256 |
14eb038337ff8b4b7db769474e9a61deb96e6011ad4a5bc1bf4359ac3df3ebbc
|