SSH Server that listens on a Unix Domain Socket instead of a TCP socket. rust and russh
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-10-27 23:47:01 +01:00
agents Bugfix B009, B011: act on the code review - SIGKILL escalation, a reap poll that cannot be deferred, safety-enforced signal helper 2026-10-27 00:42:52 +01:00
docs Bugfix B009, B011: act on the code review - SIGKILL escalation, a reap poll that cannot be deferred, safety-enforced signal helper 2026-10-27 00:42:52 +01:00
src Bugfix B009, B011: act on the code review - SIGKILL escalation, a reap poll that cannot be deferred, safety-enforced signal helper 2026-10-27 00:42:52 +01:00
tests/e2e Bugfix B009, B011: act on the code review - SIGKILL escalation, a reap poll that cannot be deferred, safety-enforced signal helper 2026-10-27 00:42:52 +01:00
.gitignore Bugfix 001: Mermaid files need to be available or the build fails 2026-10-24 20:29:39 +02:00
AGENTS.md Bugfix B009, B011: act on the code review - SIGKILL escalation, a reap poll that cannot be deferred, safety-enforced signal helper 2026-10-27 00:42:52 +01:00
Cargo.lock Feature 001, T005: exec sessions with stdout/stderr relay, exit status and signal forwarding 2026-10-24 18:56:25 +02:00
Cargo.toml Feature 001, T005: exec sessions with stdout/stderr relay, exit status and signal forwarding 2026-10-24 18:56:25 +02:00
README.md Add README.md 2026-10-27 23:47:01 +01:00

socket-ssh

An SSH server that listens on a UNIX domain socket instead of a TCP port.

Run socket-ssh to serve SSH sessions inside a sandbox or beside your own processes, reachable through the filesystem rather than the network. It supports commands, interactive PTY sessions, port forwarding and multiple channels per connection. Authentication is public-key only, ED25519 keys only. There is no privilege separation: every command runs as the user who started the server.

Capabilities

Capability Supported
Run one command: ssh host 'ls -l' Yes, as shell -c <command>
Interactive shell on a pseudo-terminal Yes, with size, terminal modes and resizes
Outbound port forwarding (ssh -L) Yes
Inbound port forwarding (ssh -R) Yes
Dynamic outbound forwarding (ssh -D) Yes
Many channels on one connection Yes, in parallel
Exit status and client signal requests Yes
SFTP, agent forwarding, password auth No

Setup

You need Rust (edition 2024) and Cargo to build. Running the end-to-end tests also needs ssh, ssh-keygen, socat, curl, timeout and kill.

cargo build

The binary lands at target/debug/socket-ssh.

Quick start

Generate a host key and a client key. Keys must be ED25519; the host key must be unencrypted.

ssh-keygen -t ed25519 -f host_ed25519 -N '' -q
ssh-keygen -t ed25519 -f client_ed25519 -N '' -q

Write a config file (see the example below), create the socket's parent directory, then start the server.

mkdir -p run
RUST_LOG=info target/debug/socket-ssh config.toml

The ssh client speaks TCP, so bridge it to the socket with socat:

socat TCP-LISTEN:24567,reuseaddr,fork UNIX-CONNECT:"$PWD/run/ss.sock" &

Connect:

ssh -p 24567 -i client_ed25519 \
    -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null \
    -o LogLevel=ERROR testuser@127.0.0.1 'echo hello'

Stop the server with Ctrl-C or kill (SIGINT, SIGTERM, SIGHUP or SIGQUIT). A deliberate stop removes the socket file.

Config file example

One TOML file is the entire interface: socket-ssh config.toml. Validation finishes before the socket is bound, so a bad field exits immediately with a message that names it.

[server]
# Inline OpenSSH private key text, not a path. ED25519, unencrypted.
# Triple quotes keep the multi-line key intact.
host_key = '''-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW
...
-----END OPENSSH PRIVATE KEY-----'''

# UNIX domain socket to bind. Its parent directory must exist.
socket_path = "/workspace/run/ss.sock"

# The only username that can authenticate.
accepted_username = "testuser"

# Shell used for commands and interactive sessions.
shell = "/bin/sh"

[environment]
# The only variables children see. Children never inherit the server's
# environment or anything the client sends.
PATH = "/usr/bin:/bin"
HOME = "/workspace"

[[authorized_keys]]
# Inline OpenSSH public key line, not a path. ED25519 only.
public_key = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIO9raMRcd98QylGSnGZquj8y9TeHT0/ILtdPR3JCh+Z3 client@host"

Config rules:

  • The host key must be unencrypted; socket-ssh cannot prompt for a passphrase.
  • shell must exist, be a regular file and be executable.
  • At least one [[authorized_keys]] entry is required.

Tests

cargo test --workspace
cargo clippy --workspace --all-targets
cargo fmt --check

The end-to-end suite in tests/e2e starts the compiled binary, bridges it with socat and drives it with an ssh client. Run cargo build first if a script calls target/debug/socket-ssh directly. The suite skips itself with a message when a required tool is missing.

Documentation

Full user documentation lives in docs/src as an mdbook:

mdbook build docs -d docs/book

It covers configuration fields and rules, environment behavior, channels and forwarding, and testing and operation.

Security

socket-ssh does no privilege separation. Whoever holds an accepted client key holds the starting user's permissions. Treat the config file, the host key and the socket's file permissions as the security boundary: anyone who can open the socket file can speak SSH to it.