Skip to content
VLOD-ZDOVPublic

About

Fast SSH replacement over QUIC (UDP) with automatic TCP fallback. Sessions survive network drops, like mosh. Same options as ssh, so scp, sftp, rsync and git work over it. Port forwarding, file copy, OpenSSH keys and certificates.

Topics

Resources

Stars

11 stars

Watchers

0 watching

Forks

Repository files navigation

quic-ssh (qsh)

qsh: SSH over QUIC. 3.4x faster connect, 3-5 MB RAM per session, 1.6x faster on lossy links

English | Русский

CI

qsh is an ssh replacement that runs over QUIC (UDP). If UDP is blocked, it falls back to TLS over TCP on its own: when QUIC has not answered within 0.7 s, TCP is tried too, and the first to connect is used. The server, qshd, listens on the same port (4422 by default) over both UDP and TCP.

Why QUIC:

  • Faster connections: on a 50 ms RTT link, running a command is 3.4× faster than with ssh (see benchmarks).
  • Better on bad networks: BBR congestion control keeps throughput up under packet loss (Wi-Fi, mobile).
  • No head-of-line blocking: every session, port forward and copy has its own stream, so a slow cp never stalls your terminal.
  • Survives client address changes (NAT rebinding).
  • Built-in keep-alive.

Features:

  • interactive shell with a PTY, window resizing and exit codes;
  • remote commands (qsh host cmd) with stdin/stdout/stderr;
  • forwarding: local (-L), remote (-R), SOCKS proxies (-D, -R port), stdio (-W), Unix sockets, X11 (-X/-Y), tunnel devices (-w), jump hosts (-J) and ProxyCommand; added and cancelled while connected with ~C or -O forward/-O cancel;
  • file copy, including directories (qsh cp -r); a single file cut off half-way goes on where it stopped when copied again;
  • the same command-line options as ssh, so sftp, scp, rsync, git and sshfs can run over qsh;
  • sessions that survive network outages: after a lost connection, qsh reconnects by itself and the shell is still there, with the output you missed;
  • compressed output: on by default, with a known risk you should read about (see Compression);
  • key login with any SSH key (Ed25519, ECDSA, RSA, security keys), ssh-agent and agent forwarding (-A), OpenSSH user and host certificates;
  • optional one-time codes (TOTP) as a second factor, built in, and optional passwords; PAM (pam_access, pam_limits, pam_systemd) in builds with the pam feature;
  • sshd's server controls: allow_users/deny_users and groups, permit_root_login, [[match]] blocks, force_command, chroot_directory with a built-in internal-sftp, banner, motd, ~/.ssh/rc, per-source penalties, qshd -t/-T and reload on SIGHUP;
  • pairing with a one-time code, so you never copy keys by hand;
  • host aliases from your existing ~/.ssh/config (qsh myserver).

Installation

Install script

Linux, macOS and Termux:

curl -fsSL https://github.com/VLOD-ZDOV/quic-ssh/releases/latest/download/install.sh | sh

It asks whether to install only the client (qsh) or the client and the server (qsh + qshd), and, for the server, whether to run qshd as a service that starts at boot (systemd, launchd, or termux-services). It puts the programs in /usr/local/bin (asking for sudo), or in ~/.local/bin when there is no sudo, and checks the download against SHA256SUMS. A service file that is already there is kept as it is. To skip the questions: ... | sh -s -- --server --service (or --client, --no-service). It also asks whether to share one connection per host for 10 minutes (ControlMaster), so that a one-time code is typed once and later qsh and qsh cp runs skip the login (--share / --no-share); the server can limit that with totp_valid_for. For the server it also asks the port and whether one-time codes are off, optional or required (--port 2222, --totp required); Enter keeps the default, s skips the question, and --defaults asks nothing more. The answers go into the config qshd creates, where everything else stays commented out.

Windows (qsh and qshd), in PowerShell:

irm https://github.com/VLOD-ZDOV/quic-ssh/releases/latest/download/install.ps1 | iex

It installs qsh.exe to %LOCALAPPDATA%\Programs\qsh and adds that folder to your PATH.

To update later, run qsh update. It installs the latest release to the same folder, updates qshd too if it sits next to qsh, and restarts a running qshd service. The restart closes the qsh sessions open on that server, so it asks first when run in a terminal; tmux, screen and nohup jobs keep running with the unit files from contrib/ (KillMode=process, as for sshd). qsh update v1.0.2 installs a given release. Releases are signed: qsh update first checks the signature of the release's SHA256SUMS against the release key built into qsh, then runs that release's installer only if its checksum is listed there, and the installer checks the archive against the same list. A release whose files were replaced, or one older than the installed qsh (unless asked for by name), is refused. Releases from before signing cannot be installed with qsh update; use the install script for them.

Prebuilt binaries

To install by hand instead: static Linux builds for x86_64 and aarch64 are on the Releases page:

ARCH=$(uname -m)   # x86_64 or aarch64
curl -fsSL https://github.com/VLOD-ZDOV/quic-ssh/releases/latest/download/qsh-$ARCH-linux.tar.gz | tar xz
sudo install -m755 qsh-$ARCH-linux/qsh qsh-$ARCH-linux/qshd /usr/local/bin/

The same archive works for both client and server. Checksums are in SHA256SUMS.

macOS

Client and server, for Apple Silicon (aarch64) and Intel (x86_64):

ARCH=$(uname -m | sed s/arm64/aarch64/)
curl -fsSL https://github.com/VLOD-ZDOV/quic-ssh/releases/latest/download/qsh-$ARCH-macos.tar.gz | tar xz
sudo install -m755 qsh-$ARCH-macos/qsh qsh-$ARCH-macos/qshd /usr/local/bin/

Downloaded with curl, the binaries carry no quarantine flag. If you download them with a browser, clear it with xattr -d com.apple.quarantine qsh qshd. To run qshd as a service, see contrib/qshd.plist. On macOS, account expiry is not checked, because macOS has no shadow database.

Windows

The client, qsh.exe, is in qsh-x86_64-windows.zip. Unzip it to a folder on your PATH. qsh uses %USERPROFILE%\.ssh (keys, config, known_hosts markers) and %USERPROFILE%\.config\qsh, and it talks to the Windows OpenSSH agent service (ssh-agent) on its own. All features except -f are available. What a Unix shell does to a command line, qsh does itself here: qsh cp expands * and ? in local paths and takes single quotes off a path ('host:logs/*.log' works in cmd.exe too), and a leading ~ in a local path (cp, -i, -F, keygen) is your profile folder. --full runs ssh.exe and waits for it. The Windows build is new and tested automatically; interactive use has seen less real-world testing than on Linux, so please report problems. The zip also has the server, qshd.exe, which serves the Windows user it runs as (see below).

qshd on Windows (new). Run qshd.exe as the user who will log in (to start it at logon: schtasks /create /tn qshd /sc onlogon /tr "%LOCALAPPDATA%\Programs\qsh\qshd.exe") and allow UDP and TCP 4422 in the firewall. Keys go in %USERPROFILE%\.config\qsh\authorized_keys; qshd pair, qshd keys and qshd totp work as on Linux. Commands run in cmd.exe (set QSHD_SHELL, e.g. pwsh.exe, for another shell); terminals use ConPTY. Copies (with resume), -L/-R/-D forwards, one-time codes, sftp (paths look like /C:/Users/me; only the read-only flag is applied of a file's mode), agent forwarding (SSH_AUTH_SOCK names a named pipe) and sessions that survive a lost connection work. Not on Windows: other users, passwords, X11 forwarding, Unix socket forwards and chroot_directory (a login it applies to is refused). The user name must be spelled as the account is. qshd does not check who else may write authorized_keys: the profile's own permissions keep other users out.

Android (Termux)

A native Android build (bionic libc, so DNS works) is in the releases as qsh-aarch64-android:

pkg install curl
curl -fsSL https://github.com/VLOD-ZDOV/quic-ssh/releases/latest/download/qsh-aarch64-android.tar.gz | tar xz
install -m755 qsh-aarch64-android/qsh qsh-aarch64-android/qshd $PREFIX/bin/
qsh pair user@server           # then: qsh ui

Termux sends taps as mouse clicks, so qsh ui works by touch: tap a host to select it, tap it again to connect.

From source

You need a recent stable Rust toolchain. No C libraries are required.

For PAM in qshd (use_pam, Linux), build with cargo build --release --features pam; that needs libpam's development files (libpam0g-dev on Debian and Ubuntu, pam-devel on Fedora). The release binaries are static and have no PAM.

git clone https://github.com/VLOD-ZDOV/quic-ssh && cd quic-ssh
cargo build --release          # target/release/qsh and target/release/qshd
sudo install -m755 target/release/qsh target/release/qshd /usr/local/bin/

Quick start

1. Server. Open port 4422 for both UDP and TCP in your firewall, then run:

sudo qshd                  # system mode: every user can log in
# or simply
qshd                       # user mode: only this user can log in

On first start it creates a host key and prints its fingerprint.

2. Pairing. On the server, as the user you will log in as:

qshd pair
# Pairing code: k7f3-9qxm  (single use, valid 10 minutes)
# On the client run this and type the code when asked:
#   qsh pair user@server

On the client:

qsh pair user@server
# Pairing code: k7f3-9qxm

The code is asked for rather than put on the command line, where other users of the client machine could read it while pairing runs. qsh pair user@server CODE still works on a machine only you use.

Already have ssh access? qsh copy-id user@server does the same without a code, as ssh-copy-id does: over your ssh login it adds this computer's key to qsh's authorized_keys there and reads qshd's host key, which it then pins (checked by ssh's own known_hosts on the way). qshd must be installed and running there.

For a phone, qshd pair --qr --host 203.0.113.10 also shows the command as a QR code: scan it with the camera and paste the text into Termux. --host sets the address in the command (by default the server's host name).

pair adds the client key on the server (~/.config/qsh/authorized_keys) and pins the server key on the client (~/.config/qsh/known_hosts). If the client has no key yet, one is created at ~/.config/qsh/id_ed25519.

3. Log in.

qsh user@server

Pairing is optional: if your key is already in ~/.ssh/authorized_keys on the server (for example, after ssh-copy-id), qsh accepts it. On first connect it shows the host fingerprint, like ssh does.

Running as a service

The install script sets this up when you answer yes. By hand:

# system mode
sudo cp contrib/qshd.service /etc/systemd/system/
sudo systemctl enable --now qshd

# user mode (no root)
mkdir -p ~/.config/systemd/user
cp contrib/qshd-user.service ~/.config/systemd/user/qshd.service
systemctl --user enable --now qshd
loginctl enable-linger "$USER"     # keep it running without an active session

The unit files are in contrib/, both in the repository and in the release archive.

Usage

qsh user@host                          # interactive shell
qsh user@host uname -a                 # run a command
qsh -t user@host htop                  # command with a forced PTY
qsh -L 8080:localhost:80 user@host     # port forward (+ shell)
qsh -N -L 5432:db.internal:5432 host   # port forward only
qsh -N -R 8080:localhost:3000 host     # remote forward: host's port 8080 -> your port 3000
qsh -N -D 1080 host                    # SOCKS4/5 proxy on localhost:1080
qsh -vv host                           # more detail: -v steps, -vv each output chunk, -vvv also QUIC and TLS
qsh -N -R 1080 host                    # SOCKS proxy on the server, connections go out from here
qsh -L /tmp/docker.sock:/var/run/docker.sock host   # Unix sockets on either side of -L/-R
qsh -J bastion user@internal           # through a jump host (both run qshd)
qsh -f -N -L 5432:db:5432 host         # log in, then go to the background
qsh -A host                            # forward your ssh-agent
qsh -Y host xterm                      # X11 forwarding (-X: untrusted, as in ssh)
sudo qsh -w 0:0 -N root@host           # tunnel devices tun0 <-> tun0 (root on both sides)
sudo qsh -w any:3 -N alice@host        # a non-root user: only a device made for them (ip tuntap add tun3 mode tun user alice)
qsh cp file.txt user@host:dir/         # upload
qsh cp a.txt b.txt user@host:~/inbox   # several files into a directory (~ is the home directory)
qsh cp user@host:logs/app.log .        # download
qsh cp 'user@host:logs/*.log' .        # wildcards (* and ?) in a remote path; needs qshd 2.1 or newer
                                       # (* skips names that start with a dot, as in a shell: use .* for those)
qsh cp -r project/ user@host:src/      # copy a directory (either direction)
qsh cp -C logs.txt host:               # compressed (zstd), for text on slow links
qsh cp big.iso host:                   # cut off? run it again: it goes on where it stopped
qsh multi -g web -- uptime             # one command on several hosts
qsh -p 2222 user@host                  # another port (or user@host:2222)
qsh --transport tcp user@host          # force TCP (or quic)
qsh -v user@host                       # show which transport is used
qsh -G myserver                        # print the resolved settings for a host
qsh keygen                             # create ~/.config/qsh/id_ed25519 (or: qsh keygen FILE)
qsh --full myserver                      # OpenSSH-compatible mode, see below
qsh ui                                 # host menu with status and speed test
qsh -N -R 2222:localhost:22 server --save tun   # connect and keep it: later `qsh tun`, also in qsh ui
qsh -O check myserver                  # the shared connection (see below)
qsh doctor myserver                    # does not connect? checks each step and says what to fix
qsh -v myserver                        # each step of the connection and login, as ssh -v
qsh forget myserver                    # the host key changed on purpose: forget it (as ssh-keygen -R)
qsh completions fish > ~/.config/fish/completions/qsh.fish   # Tab completes commands and hosts
                                       # bash: source <(qsh completions bash) in ~/.bashrc; zsh: the same with zsh
qsh update                             # install the latest release (qshd too, if it is next to qsh)
All supported ssh options

Options work as in ssh: they can be combined (-tt, -NL…), placed after the host, and given with or without a space (-p22). Also supported: -l user, -o Key=value, -F configfile, -4/-6, -q, -n, -s (subsystem), -g (let other hosts use local forwards), -e (escape character), -T/-t/-tt, -b and -B (the local address or interface connections leave from). ssh options that mean nothing for qsh (ciphers, MACs, key exchange, GSSAPI, -C and the like: qsh always uses TLS 1.3) are accepted and ignored (-v lists them); for compressed copies use qsh cp -C. Other ssh options qsh does not carry out (-E, -I, -o PubkeyAuthentication, -o VerifyHostKeyDNS, -o GatewayPorts...) give a warning once qsh has connected (not with -q). -Q, -o RevokedHostKeys, -o PermitRemoteOpen and -o RefuseConnection are refused, since without them qsh would be less strict than asked; so is a host whose config sets RevokedHostKeys, and with PermitRemoteOpen in the config a dynamic -R port. As in ssh, an unknown -o keyword is an error, unless -o IgnoreUnknown names it. With --full, qsh hands all of these to ssh instead, except RefuseConnection in a config and a bad keyword, RevokedHostKeys or a refusal that may apply in ~/.config/qsh/config (ssh does not read that file): they stop qsh either way.

In a session, ~. at the start of a line disconnects, even when the server no longer responds. ~C opens a command line to add forwards (-L, -R, -D) or cancel them (-KL, -KR, -KD), ~# lists them, ~^Z suspends qsh, ~? lists the escapes and ~~ sends a literal ~.

Keys, ssh-agent and certificates

qsh logs in with the same keys as ssh, in this order:

  1. The TLS handshake key: the first Ed25519 key among -i, the config's IdentityFiles, ~/.ssh/id_ed25519 and ~/.config/qsh/id_ed25519. If the server accepts it, the login takes no extra round trip.

  2. Otherwise, as in ssh:

    • certificates (<key>-cert.pub, CertificateFile);
    • the keys in your ssh-agent (SSH_AUTH_SOCK, IdentityAgent; IdentitiesOnly is honoured);
    • key files of any type: -i/IdentityFile, or by default ~/.ssh/id_rsa, id_ecdsa, id_ed25519.

    qsh first asks the server which keys it would accept, so a security key is only touched for a key that works. The signature is bound to the TLS session.

Security keys (sk-ssh-ed25519, sk-ecdsa) work through ssh-agent (ssh-add ~/.ssh/id_ed25519_sk). Encrypted keys prompt for their passphrase. SSH_ASKPASS and SSH_ASKPASS_REQUIRE work as in OpenSSH.

-A (or ForwardAgent yes) makes your agent available on the server through SSH_AUTH_SOCK. The socket sits in a private directory owned by you. As with ssh, root on the server can use the keys in your agent while the session lasts, so forward it only to hosts you trust (or use ProxyJump). qsh cannot bind the forwarded agent to hosts (OpenSSH's session-bind needs an SSH session), so keys added with ssh-add -h cannot be used through it: ssh-agent refuses them on an unbound connection.

Sessions that survive disconnects

A terminal session (a login shell, or a command with -t) is kept by the server for an hour after the connection is lost:

  • qsh notices the loss within about 15 s, reconnects by itself, and shows the output you missed. Full-screen programs redraw.
  • Wi-Fi to mobile switches, laptop sleep and short outages no longer kill your shell. Over QUIC, a change of address (NAT rebinding) usually needs no reconnect at all.
  • Keys typed during an outage are dropped, and ~. gives up waiting.
  • Nothing is dropped while you are connected: a program that writes faster than your terminal shows waits for it, as over ssh, and a paste of any size arrives whole. While you are away, the last 1 MiB of output is kept; programs go on running, but one that floods its terminal is slowed down instead of keeping a core busy.
  • Up to 16 such sessions per user. At the limit, a new one closes the session that has been detached the longest (one left behind by a killed client, say).
  • Quitting normally (exit, ~., closing the terminal) ends the session on the server as usual.
  • Turn it off with PersistSession no in ~/.config/qsh/config (or -o PersistSession=no). Port forwards and the forwarded agent survive with the session (with qshd 1.5 or newer; an older qshd ends them and qsh says which): -L and -D keep listening, -R and the agent come back on the new connection, and only connections open through them at that moment are lost. Sessions with X11 forwarding or a tunnel (-w) are not kept.
  • -N survives too, with qsh and qshd 1.6 or newer: the forwards come back after a lost connection, with one-time codes on as well.
  • A reconnect that takes longer than 10 s says why and when the next try is.
  • With RestoreSession yes in ~/.config/qsh/config, a terminal session also outlives qsh itself: if qsh is killed or its terminal is closed, the next plain qsh host goes back to the session while the server keeps it (session_timeout). A window that is still open keeps its session. It is off by default: the session's token then sits in a private file under ~/.config/qsh/sessions, and that file plus your key get back into the session without a one-time code.
  • After ^C, at most about 1 MiB of output that was already on its way scrolls by (ssh: about 2 MiB), in every terminal session with qshd 1.0.5 or newer.
  • ServerAliveInterval and ServerAliveCountMax set how quickly a dead connection is noticed. For other sessions they work as in ssh. qsh asks with pings on streams of their own, so output nobody reads yet, or input the remote command does not read yet, never makes a working connection look dead.

Compression

Terminal and command output is compressed with zstd when qsh and qshd are 1.6 or newer. It costs next to nothing and matters most when output outruns a slow link: there, ^C or a key takes effect in about half a second instead of ten. Full-screen programs repeat most of each screen, so btop or hollywood send 15 to 30 times less. Short lines, as from tail -f, shrink about 2 times. Output that does not shrink goes as it is, and a typed character's echo is never touched. Compression no in ~/.config/qsh/config or ~/.ssh/config, or -o Compression=no, turns it off. qsh cp has its own switch, -C.

Compression is useful, but it can reveal data. It has a known weakness, the one behind CRIME, BREACH and VORACLE: encryption hides content but not length, so someone who watches the traffic and can also put text on your screen, for example into a log you are following, may guess a secret shown there from how well the guess compresses. qsh defends against this in several ways:

How qsh limits the risk
  • What looks like a secret never enters the compression context: long random tokens, and the values after words like password, token, secret, session, Cookie and Authorization. These cannot be guessed this way at all.
  • Sizes are rounded to 16 bytes, with a random step added, so a single match does not show.
  • The context lasts as long as the stream. A clean start is what such an attack needs, so a session that keeps losing its connection (5 times in 10 minutes, or 32 times in all) stops compressing.

A secret that does not look like one, such as a plain word with no such keyword before it, is covered only by the last two, which make guessing slow and not impossible. On a host where that matters, and where others can write to what you watch, set Compression no.

Connection sharing (ControlMaster)

Like ssh, qsh can keep one connection and run later sessions, commands and copies to the same host through it, without a new handshake and login:

# ~/.config/qsh/config
Host *
    ControlMaster auto
    ControlPersist 10m
  • ControlMaster auto: use a running master, or become one. yes (or -M) always becomes one. The default no uses a master only if ControlPath is set.
  • ControlPersist 10m keeps the master in the background for 10 minutes after the last session (yes until -O exit); connections through the master's own forwards count as sessions. Without it the first qsh is the master and, when its own session ends, waits for the others.
  • The socket is in ~/.config/qsh/ctl/ by default (ControlPath, or -S path; tokens %h %p %r %C). ssh's ControlPath is not used: those sockets speak ssh's protocol.
  • qsh -O check host, -O exit, -O stop, -O forward -L ... and -O cancel -L ... as in ssh.
  • A run's -R goes through the master, which takes it back when the run ends, however it ends (unlike ssh, where it stays until the master exits). A master whose own session ends takes back its own forwards before it waits for the others. Runs with -A or -X use a connection of their own. A terminal session started through a master survives the master: qsh logs in by itself and resumes it. A master whose own terminal session reconnects keeps sharing the new connection.
  • Not on Windows.

Host aliases (~/.ssh/config)

qsh reads your existing ~/.ssh/config, so hosts you already use with ssh work by name:

# ~/.ssh/config
Host myserver
    HostName 203.0.113.10
    User root
    IdentityFile ~/.ssh/work_key
qsh myserver                        # = qsh -i ~/.ssh/work_key root@203.0.113.10
qsh cp backup.tar myserver:/srv/

For qsh-specific settings, including the port, use ~/.config/qsh/config with the same syntax; its values take precedence. What it leaves unset comes from ~/.ssh/config and /etc/ssh/ssh_config, ForwardAgent, StrictHostKeyChecking and PasswordAuthentication included. Exceptions: ControlPath, RestoreSession and the known_hosts settings come only from qsh's file, and ProxyJump/ProxyCommand there only make --full hand the host to ssh; Port (the SSH port) and the other settings of the ssh session itself (RequestTTY, RemoteCommand, SendEnv...) are used only with --full. Hosts saved by qsh ui win over blocks for many hosts (Host *), but never over a block of yours that names the host. qsh -G host shows the result. qsh creates it at its first start with every setting commented out at its default, with a note on each (the template is contrib/qsh_config); an existing file is never changed:

# ~/.config/qsh/config
Host myserver
    Port 8080
Supported config keywords

Supported: Host patterns (*, ?, !), HostName, User, Port, IdentityFile, LocalForward, RemoteForward, DynamicForward, RequestTTY, BatchMode, StrictHostKeyChecking, EscapeChar, AddressFamily, LogLevel, IdentitiesOnly, IdentityAgent, CertificateFile, ForwardAgent, ServerAliveInterval, ServerAliveCountMax, PersistSession, PredictiveEcho and LoopbackFallback (qsh only; a -R target refused on 127.0.0.1 tries ::1 and back, off by default as another local user may listen there), Compression (for qsh cp), ControlMaster, ControlPersist, ControlPath (in ~/.config/qsh/config), ProxyJump and ProxyCommand (in ~/.config/qsh/config; qsh then runs over the program's stdin/stdout, e.g. ProxyCommand qsh -W %h:%p bastion), SendEnv, SetEnv, RemoteCommand, SessionType, StdinNull, ForkAfterAuthentication, ExitOnForwardFailure, LocalCommand with PermitLocalCommand, HostKeyAlias, ConnectTimeout, ConnectionAttempts, UserKnownHostsFile and GlobalKnownHostsFile (default /etc/qsh/known_hosts), KnownHostsCommand and HashKnownHosts (in ~/.config/qsh/config), AddKeysToAgent, PasswordAuthentication, NumberOfPasswordPrompts, ForwardX11, ForwardX11Trusted, ForwardX11Timeout, XAuthLocation, Tunnel, TunnelDevice, Tag (or -P), CanonicalizeHostname with CanonicalDomains, CanonicalizeMaxDots and CanonicalizeFallbackLocal, BindAddress, BindInterface, RefuseConnection, IgnoreUnknown, Include and Match (all, host, originalhost, user, localuser, exec, localnetwork, tagged, canonical, final). A Match block whose conditions qsh cannot check (version...) is not used, but a ProxyCommand, ProxyJump, RevokedHostKeys, RefuseConnection or PermitRemoteOpen in it still counts, so qsh never connects around a proxy or a refusal that may apply (also from a file such a block includes). Keywords are read in any case (localforward); Host patterns fold case in ~/.config/qsh/config but not in ssh's files, as in ssh; yes/no values also as on/off, true/false or 1/0, and LocalForward also in the -L form (LocalForward 8080:localhost:80). In ~/.config/qsh/config, as in ssh, an unknown keyword (a typo) is an error unless IgnoreUnknown names it, so is a value that is none of a setting's choices (BatchMode maybe), and an ssh keyword qsh does not carry out gives a warning with file and line (not with -q); ~/.ssh/config and /etc/ssh files are left to ssh. known_hosts entries may be hashed (ssh-keygen -H) or patterns. As with ssh, /etc/ssh/ssh_config is read after ~/.ssh/config (not with -F), # starts a comment anywhere on a line, and config files (and their Includes) that other users could write are refused; unlike ssh, so is /etc/ssh/ssh_config itself. Command-line values (user@, -l, :port, -p, -i) always win; the user from the command line is also what Match user and %r see.

OpenSSH-compatible mode (--full)

With --full (automatic when qsh is installed as ssh), qsh behaves like a drop-in for ssh:

  • It also reads Port and RequestTTY from ~/.ssh/config. Without --full, these describe the ssh session and are ignored. LocalForward, RemoteForward and DynamicForward from there apply either way.
  • It looks for qshd both on the ssh port (default 22) and on 4422, in parallel, and uses whichever answers. On 22, qshd can run UDP-only next to sshd (tcp = false in the server config). An explicit qsh port (-p, :port or Port in ~/.config/qsh/config) means only that port is tried.
  • If no qshd answers within 1 s, or ~/.ssh/config gives the host a ProxyJump/ProxyCommand (the hops may not run qshd), qsh runs the regular ssh (or scp for qsh --full cp) with the same arguments. ssh then applies its whole config itself: agent, jump hosts, its own known_hosts.
  • Hosts without qshd are remembered for an hour, so later connections go straight to ssh. --transport quic forces a new check.
  • What qsh cannot parse (ssh -Q kex, -O forward, a user name like user@corp.example) also goes to ssh. A name that only qsh's own config knows (a connection saved in qsh ui, say) gets its HostName, User and IdentityFile passed to ssh, so ssh reaches the same host.
  • A wrong host key or a refused login never falls back to ssh. Neither does a host known on one candidate port that presents a different key on the other: it is refused.
qsh --full myserver               # QUIC if qshd is there, otherwise plain ssh
qsh --full -v myserver            # prints which one was used

OpenSSH tools over qsh

Programs that run ssh underneath can use qsh instead:

sftp -S qsh user@host                         # needs sftp-server on the server (package openssh-sftp-server)
scp -S qsh file.txt user@host:dir/
rsync -a -e qsh project/ user@host:src/
GIT_SSH_COMMAND=qsh git clone user@host:repo.git
sshfs -o ssh_command=qsh user@host:/srv /mnt/srv

To make every program use qsh, install it as ssh earlier in your PATH. Run as ssh, qsh turns on --full, so hosts without qshd are still reached with the real ssh:

ln -s "$(command -v qsh)" ~/.local/bin/ssh

Hosts without an open port

A host behind NAT, or one you cannot open a port on, can keep a tunnel to any host with qshd that you can reach:

# on the hidden host (as the user who will log in there):
qsh -N -o ExitOnForwardFailure=yes -R 14422:127.0.0.1:4422 user@public.example.com
# from anywhere:
qsh -J user@public.example.com you@localhost:14422

The session stays encrypted end to end: the public host only passes the bytes on, and the hidden host's key is checked as usual. The port on the public host listens on loopback only. To keep the tunnel up, use contrib/qsh-tunnel@.service (a systemd user unit; instructions inside).

Experimental: qsh punch. If no public host is available, qsh punch tries to open the NAT itself: both sides learn their public address from STUN, exchange it in a chat message, and then send UDP packets to each other until the mappings line up, with a normal qsh connection running through the hole. It works through cone NATs; symmetric NAT and most CGNAT defeat it, and there is no relay fallback. See docs/hole-punch.md.

Host menu and speed test (qsh ui, qsh speed)

qsh ui opens a connection menu with every host from ~/.ssh/config, ~/.config/qsh/config, known_hosts and the connections you saved in it:

Menu keys and features
  • Status: each host is checked in the background for qshd (TLS handshake with a throwaway key, no login). The list shows ● quic 42 ms, ● tcp (UDP blocked) or ○ ssh (no qshd), and whether the host key is known, new or changed. Results are cached for 10 minutes in ~/.config/qsh/ui-state.toml, so reopening the menu does not contact every server again; r checks everything now.
  • Connecting: ⏎ / tap connects (with --full by default, so hosts without qshd open with plain ssh). When the session ends you return to the menu. Recently used hosts move to the top.
  • One-off connection: c connects once to user@host[:port] without saving anything.
  • Saved connections:
    • n adds one: name, address, user, port, key file, ssh options, transport (auto/QUIC/TCP), and whether to fall back to ssh. ssh options takes ssh's own flags, such as -L 8080:localhost:80 -D 1080 -A -C or -o ServerAliveInterval=30; they are saved as config lines (LocalForward and so on), and ssh gets them too when it takes over.
    • e edits a saved connection, and d deletes it.
    • From the command line, --save NAME after the host keeps a connection with its port, user, key, forwards and other options, and then connects as usual. A name that is already saved needs --force. A remote command, -W, -g and --transport are not saved (qsh says so).
    • They are stored in ~/.config/qsh/ui-hosts (ssh_config syntax), so qsh NAME works on the command line too.
    • Your own config files are never written. For a host from them, e only changes the menu's settings (transport, ssh fallback), and a saved name cannot clash with a host of yours.
  • History: Tab shows the history with the result of each connection. ⏎ connects again, a saves an entry as a connection, d removes it.
  • Groups: the e form has a groups field (e.g. web prod), for any host. Groups show as #web tags. /#web shows exactly that group (plain /web matches names, addresses and groups containing "web"), and x runs one command on every host shown (qsh multi; without a filter, on all of them). They are kept in ~/.config/qsh/groups.
  • Speed test: s runs it with a speedometer: latency (5 pings), then 5 s download and 5 s upload, with a live needle and graph.
  • Port forwards: f lists the host's forwards. a adds one by picking what it does (open a server's port here, share a port of this machine with the server, or a SOCKS proxy) and typing the ports; d removes one; ⏎ connects with them and t opens just the tunnel, without a shell. A saved connection keeps its forwards; for other hosts, added ones are for the next connection only.
  • Other keys: p pairs with a code from qshd pair, / filters, ? lists every key (the footer of a narrow screen has room for only a few), q quits.
  • Screens: the layout adapts to narrow phone screens, and the mouse and touch work (scroll, tap).

qsh multi runs a command on several hosts at once, each line prefixed with the host, and lists the hosts where it failed:

$ qsh multi -g web db1 -- uptime
web1 | 10:21:07 up 12 days,  load average: 0.08, 0.03, 0.01
web2 | 10:21:07 up 40 days,  load average: 0.31, 0.25, 0.20
db1  | 10:21:07 up 3 days,  load average: 1.02, 0.97, 0.90
ok on all 3 hosts

Hosts run in parallel (-P 16 by default) with BatchMode, so nothing can stop to ask a question: use keys that need no passphrase prompt (or an agent) and hosts already in known_hosts (or --accept-new-host). The words after -- are joined and run by the remote shell, as with ssh: qsh multi -g web -- 'cd /srv && git pull'. The exit code is 0 if the command succeeded everywhere, 1 if it failed somewhere, and 255 if qsh itself failed on a host (it could not connect or log in, or the command exited with 255). With --json, the output comes as one JSON array at the end (host, exit, stdout and stderr lines), for scripts; qsh doctor --json does the same for its checks.

qsh speed host runs the same test in plain text:

$ qsh speed myserver
root@203.0.113.10:4422 over quic
ping          79.3 ms  (min 78.9, max 81.2)
download     107.2 Mbit/s  (64.0 MiB in 5.0 s)
upload        70.1 Mbit/s  (41.8 MiB in 5.0 s)

Keystroke timing protection

In interactive sessions qsh hides the rhythm of your typing from anyone watching the network, like OpenSSH's ObscureKeystrokeTiming:

  • How it works: while you type, packets leave on a fixed 20 ms clock and all have the same size. Ticks with nothing to send carry fake keystrokes ("chaff"), which also continue for a random 1–2 s after you stop, and the server answers chaff like a real echo. Pastes and command output are not affected.
  • Why it matters: without it, the gaps between keystrokes are visible on the wire. Measured over many sessions, they can narrow down passwords typed inside the session (sudo, su) and show which commands are being typed.
  • Cost (measured): keystrokes reach the server 10 ms later on average, at most 20 ms. The first key after a pause is sent at once. While typing, about 6× more small packets (≈50/s each way, a few KB/s). There is no cost when idle and for bulk data.
  • Settings: ObscureKeystrokeTiming no or ObscureKeystrokeTiming interval:40 in ~/.config/qsh/config (or ~/.ssh/config). Only interactive sessions with a PTY are affected.

Typing on slow links (echo prediction)

Like mosh, qsh shows what you type before the server's echo arrives, when echoes take longer than about 30 ms:

  • qsh keeps a copy of the screen as the server drew it. A typed character is drawn at the cursor only on an empty cell, and only after an earlier keystroke on the same line came back exactly as predicted.
  • Enter, arrows, Ctrl keys and the like start over, and so does any output your typing did not cause (a prompt appearing): after a password prompt nothing is shown until the server itself echoes a character, so a hidden password is never drawn. A wrong guess, or a * echo of a masked prompt, confirms nothing until the next Enter or control key.
  • Output the emulator does not model (insert mode, repeated characters, saved cursor positions) pauses prediction until the screen is redrawn. Colored backgrounds and other scripts than Latin are not predicted.
  • When the server's output differs, the predicted characters are erased before it is shown, so the screen always ends up exactly as the server drew it.
  • PredictiveEcho auto (default), yes (also on fast links) or no, in ~/.config/qsh/config or with -o.

Locked-down build

Everything qsh and qshd can do is a Cargo feature, on by default, so a build can leave parts out. Requests for what was left out are refused before any of their code runs, and no setting in qshd.toml or a [[match]] block turns them back on. The release binaries have everything.

scripts/build.py is a menu for it (Python 3, nothing to install; Linux and macOS): tick the features, see which source files the build uses and what it warns about, press Enter to build. Tab goes to qshd's settings; what you change there is written to a qshd.toml beside the programs.

scripts/build.py                               # the menu, starting from the hardened profile
scripts/build.py --profile minimal --build     # without the menu
scripts/build.py --profile hardened --features +root-login --print   # only show the cargo command
scripts/build.py --profile forward-only --map  # which files that build uses
Profile What it has
hardened shell, exec, files, compress, persist, tofu, predict, forwarding, pair, and the hardened defaults
full everything, as in the releases
minimal shell and exec: a shell and commands over QUIC or TCP, keys and certificates only, to hosts whose key is already known
forward-only forwarding: port forwards with -N, no sessions

Without the script, name the features yourself:

cargo build --release --no-default-features --features shell,exec          # minimal
cargo build --release --no-default-features --features shell,exec,files,persist

--no-default-features alone now leaves out sessions too (up to 1.10 a shell and commands were always there): add shell,exec.

Leaving out shell alone is not a restriction: with exec, qsh host bash still gives a shell, because a shell is a command like any other. It only refuses logins without a command. To have no shell at all, leave out both (forwards and file copies remain; qshd then starts its copy helpers and its own SFTP server directly instead of through the user's shell, whose startup files a copy could change, and other [subsystems] are not offered), or give keys a forced command (command="..." in authorized_keys).

The hardened feature changes what qshd starts from; the config file can still set each value:

Setting Usual hardened
max_auth_tries 6 3
login_grace_time 120 30
max_startups_per_ip 8 4
max_sessions 10 4
session_timeout 3600 600
allow_tcp_forwarding, allow_stream_local_forwarding true "local" (no -R)
require_post_quantum false true (no clients older than 2.0)

The hardened profile has no root-login: root cannot log in at all, not even with a key. Before installing it on a server you reach as root, set up a user with a key and sudo, or add root-login.

Feature What it adds
shell login shells (qsh host)
exec commands (qsh host command, qsh multi, forced commands)
tofu trusting a host key seen for the first time (asking, or --accept-new-host)
pair pairing codes (qsh pair, qshd pair)
password password logins on qshd
root-login root logins (as permit_root_login says; without it root never logs in)
user-rc ~/.ssh/rc
files qsh cp, sftp and other subsystems
compress zstd for copies and session output
forwarding -L, -R, -D, -W, Unix sockets
agent, x11, tunnel -A, -X/-Y, -w
persist sessions that survive a lost connection (resume tokens)
sharing ControlMaster
speed qsh speed
punch qsh punch (NAT traversal through public STUN servers)
ui, predict qsh ui, echo prediction
self-update qsh update
hardened stricter qshd defaults (above); off by default

qshd -t lists what the running build was made without. Without tofu, add host keys to known_hosts yourself (or use a @cert-authority); without pair, add client keys to authorized_keys. A smaller program has less that can go wrong, but no build can promise that it has no bugs: keep it updated.

Server configuration

Mode Run as Who can log in Files
system root any user (with their own keys) /etc/qsh/config.toml, /etc/qsh/host_ed25519
user a regular user only that user ~/.config/qsh/qshd.toml, ~/.config/qsh/host_ed25519

At the first start (or qshd init) qshd creates the config with every setting commented out at its default (the template is contrib/qshd.toml): readable by all in /etc/qsh, like sshd_config, private in user mode. An existing file is never changed. Yes/no settings take true/false, yes/no, on/off or 1/0; choices are read in any case ("No", "ClientSpecified"), times in seconds or with a unit ("90s", "5m", "1h30m", "1d"), and numbers also in quotes. All settings, at their defaults:

Full config with comments
listen = "[::]:4422"            # UDP and TCP; falls back to 0.0.0.0 if IPv6 is disabled
# host_key = "/etc/qsh/host_ed25519"
use_ssh_authorized_keys = true  # also accept ~/.ssh/authorized_keys
use_qsh_authorized_keys = true  # ~/.config/qsh/authorized_keys (false: only the files below)
allow_tcp_forwarding = true     # or "no", "local" (-L/-D/-W only), "remote" (-R only)
max_connections = 256
max_startups = 64               # unauthenticated connections at once (like sshd's MaxStartups)
max_startups_per_ip = 8         # ... from one IP address
connection_buffer_mb = 32       # per connection: data held for programs that have not read it yet. Usually
                                # near 0; it fills when forwards stop reading (up to 1/8 of it each), and when full
                                # the whole connection waits. RAM at worst: max_connections × this (256 × 32 MiB
                                # = 8 GiB), plus up to 256 KiB per open stream over TCP. Small VM: 8-16; busy proxy: 64-256
require_post_quantum = false    # true: only the post-quantum key exchange; clients older than qsh 2.0 cannot connect
session_scope = true            # as root under systemd: each session in its own scope in user-UID.slice, so
                                # `systemctl status qshd` shows qshd itself and restarting it leaves tmux running
tcp = true                      # false: UDP only, e.g. on port 22 next to sshd for `qsh --full`
gateway_ports = "no"            # -R listens on loopback only; "yes": all addresses; "clientspecified"
loopback_fallback = false       # -L/-D refused on 127.0.0.1 tries ::1 and back; off: another user may listen there

max_auth_tries = 6              # failed key proofs per connection
allow_agent_forwarding = true
totp = "optional"               # one-time codes: "off", "optional" (for users who set them up), "required"
totp_valid_for = 3600           # seconds a code lasts on its connection (0: as long as it); then it starts no
                                # new sessions or copies, so a shared connection (ControlMaster) logs in again with
                                # a code. What is under way goes on, forwards included: a -L port keeps working
session_timeout = 3600          # seconds a disconnected terminal session is kept; 0 = off
# trusted_user_ca_keys = "/etc/qsh/user_ca.pub"   # CAs that sign user certificates (principal = user name)
# host_certificate = "/etc/qsh/host_ed25519-cert.pub"   # used automatically if it exists
# revoked_keys = "/etc/qsh/revoked_keys"   # keys that may not log in: a key list or a KRL (ssh-keygen -k)
# authorized_keys_command = "/usr/local/bin/get-keys %u"   # more keys from a program, like sshd's
# authorized_keys_command_user = "nobody"                 # it runs as this user (required as root)

# Who may log in (checked in this order, like sshd): patterns, `user@address` with CIDR
# deny_users = ["guest"]
# allow_users = ["alice", "bob@192.0.2.0/24,!192.0.2.9"]
# deny_groups = ["nossh"]
# allow_groups = ["staff"]
permit_root_login = "prohibit-password"   # root with keys only; "yes", "no", "forced-commands-only" (keys with command=)
password_authentication = false # accept /etc/shadow passwords when no key works (system mode, Linux; not expired ones)
permit_empty_passwords = false
use_pam = false                 # PAM account checks, passwords and sessions (built with --features pam; system mode, Linux)
pam_service = "qshd"           # its file in /etc/pam.d (see contrib/qshd.pam)
login_grace_time = 120          # seconds to log in; 0 = no limit
# banner = "/etc/issue.net"     # shown before login
print_motd = true               # /etc/motd for login shells (~/.hushlogin turns it off)
print_last_log = true           # "Last login: ..." (system mode, from lastlog or wtmp)
permit_user_rc = true           # run ~/.ssh/rc via the user's shell (not for subsystems or under force_command), else /etc/ssh/sshrc
max_sessions = 10               # sessions at once per connection
permit_tty = true
accept_env = ["LANG", "LC_*", "COLORTERM"]   # variables clients may set
# force_command = "/usr/local/bin/menu"   # replaces any command; the original is in SSH_ORIGINAL_COMMAND
# chroot_directory = "/srv/jail/%u"       # confine sessions and qsh cp (system mode; root-owned path)
# permit_open = ["db.internal:5432"]      # -L/-D/-W destinations; "none" = none; set: no Unix sockets
# permit_listen = ["8080", "localhost:9000"]   # -R listeners; set: no Unix sockets
disable_forwarding = false      # true: no port, socket or agent forwarding at all
allow_stream_local_forwarding = true   # Unix socket forwarding: or "no", "local", "remote"
stream_local_bind_mask = "0177" # permissions taken from -R sockets on the server
stream_local_bind_unlink = false   # remove a stale socket file before listening
x11_forwarding = false          # allow qsh -X/-Y (DISPLAY=localhost:10 and up)
x11_display_offset = 10
x11_use_localhost = true
xauth_location = "/usr/bin/xauth"
permit_tunnel = "no"            # qsh -w: "yes", "point-to-point" (TUN), "ethernet" (TAP); Linux, macOS; as in sshd, other users only a device made for them (Linux)
client_alive_interval = 0       # seconds between probes of a silent client; 0 = built-in (~60 s)
client_alive_count_max = 3
per_source_penalties = true     # drop addresses that keep failing; or "authfail:5s noauth:1s min:15s max:10m"
# per_source_penalty_exempt_list = ["192.0.2.0/24"]
# authorized_keys_file = [".ssh/authorized_keys", "/etc/ssh/keys/%u"]   # read with use_ssh_authorized_keys
# authorized_principals_file = ".ssh/principals"   # principals for trusted_user_ca_keys certificates

# Global settings go above this line: every key below a table header belongs to that table.
[set_env]                       # variables every session gets
# TZ = "UTC"

[subsystems]                    # for `qsh -s` and sftp; run as `$SHELL -c command`
# sftp = "internal-sftp"       # built-in server; default (through the user's shell) when OpenSSH's sftp-server is not installed

# Settings for some logins, like sshd's Match (user, group, address; all given must hold).
# If several blocks match, the first one that sets a setting wins; "none" removes a value.
# An empty user/group/address is an error; a list of only "!" entries matches no one
# (write "*,!root"); addresses are IPs or ranges, host names never match.
# [[match]]
# group = "sftponly"
# chroot_directory = "/srv/sftp/%u"
# force_command = "internal-sftp"
# disable_forwarding = true
# permit_tty = false
SFTP, chroot, forwarding, reloading, penalties

SFTP and chroot. qshd has a built-in SFTP server, internal-sftp, like sshd's: it needs no shell (it works for accounts with a nologin shell) and no files inside a chroot. Use it as the sftp subsystem or as force_command, with sshd's options -R (read-only), -u UMASK and -d DIR (start directory; %u user, %d home). It is also used for sftp when OpenSSH's sftp-server is not installed, started through the user's shell then, so nologin and git-shell accounts get no SFTP that way. qshd runs it built in only where the server names it (a subsystem, force_command, a key's command=); a client asking to run internal-sftp gets the user's shell like any command. chroot_directory confines a login's programs and its qsh cp transfers to a directory; as with sshd, the directory and all above it must belong to root and be writable by nobody else, or the login fails. The classic SFTP-only setup is the [[match]] block above.

Remote forwards (-R) listen where gateway_ports allows, and users other than root cannot listen on ports below 1024. allow_tcp_forwarding = false turns off -L, -R, -D and -W.

Checking and reloading. qshd -t checks the config and the host key; qshd -T prints the settings in effect, and qshd -T -C user=alice,addr=192.0.2.7 those for one login (with [[match]] applied, and whether the user may log in at all; addr= is required when a [[match]] or a user@host entry tests the address). Both say which file they read: without root that is the user-mode config, not /etc/qsh/config.toml. They also list each [[match]] block that changes who may log in or how, e.g. [[match]] #2 (user = backup) changes password_authentication: false -> true; qshd logs the same lines at startup and after a reload, so a setting that ended up inside a block by mistake shows. A setting name inside [set_env] or [subsystems] (written below the table header) is an error. On SIGHUP (systemctl reload qshd) qshd reads its config again: new logins use the new settings, running sessions keep theirs. A broken or missing config is reported and the old one kept; a -c file that does not exist is an error too. Changes to listen, tcp, the host key, host_certificate, the connection limits, per_source_penalties, per_source_penalty_exempt_list, session_scope, session_timeout and client_alive_* take effect after a restart.

Penalties. As in sshd 9.8 and newer, an address whose connections fail to log in collects penalty time (5 s per failed login, 1 s for a connection that never tries, 10 s for running out of login_grace_time); once it has 15 s, its new connections are dropped until the time runs out (at most 10 minutes). IPv6 addresses count per /64. Unknown users and refused pairings count like failed logins, so penalties do not tell which accounts exist.

Users that deny_users/allow_users/deny_groups/allow_groups or permit_root_login = "no" keep out are treated like unknown users: they get the same "access denied", so the answer does not tell which accounts exist.

User keys live in ~/.config/qsh/authorized_keys (unless use_qsh_authorized_keys = false) and, if enabled, ~/.ssh/authorized_keys. All key types work, except DSA and RSA below 2048 bits. These options are enforced:

  • command= (the original command goes to SSH_ORIGINAL_COMMAND; file transfer is refused);
  • from= (addresses and CIDR);
  • restrict, no-pty/pty, no-port-forwarding/port-forwarding, no-agent-forwarding/agent-forwarding;
  • permitopen=, permitlisten=, expiry-time=;
  • cert-authority with principals=;
  • no-touch-required, verify-required.

A line with any other option is not used at all: a restriction qsh cannot enforce never turns into access.

Certificates, keys from a program, revoking keys, one-time codes, PAM

Certificates. Sign keys with ssh-keygen -s ca -I id -n USER key.pub, then trust the CA either server-wide (trusted_user_ca_keys) or per user with a cert-authority line. force-command, source-address and the permit-* extensions are enforced. For host certificates, sign the host key (ssh-keygen -s ca -I host -h -n host.example.com /etc/qsh/host_ed25519.pub) and add @cert-authority *.example.com <CA key> to ~/.config/qsh/known_hosts or ~/.ssh/known_hosts on clients: hosts with a valid certificate are trusted without the first-connection question. @revoked lines are honoured. Certificates without an expiry date (ssh-keygen without -V) work too. As with OpenSSH, a host whose certificate comes from a revoked CA, or from a trusted CA but is expired or made for another name, is refused even if its key is in known_hosts.

Keys from a program. authorized_keys_command works like sshd's AuthorizedKeysCommand: its output is read like an authorized_keys file, in addition to the files. Tokens: %u user, %h home, %U uid, and for the offered key %f (fingerprint), %k (base64), %t (type). With a key token it runs once per offered key. The program needs an absolute path that only root can change (in user mode: root or the server's user), runs with a 10 s limit, and as root only as authorized_keys_command_user.

Revoking keys. revoked_keys names a file with public keys (one per line) or a KRL made with ssh-keygen -k, which can also revoke certificates by serial number or key ID, and whole CAs. It is read at every login, so changes apply at once. If the file is set but cannot be read, no key is accepted.

Paired keys. qshd keys, as the user on the server, lists the keys that may log in through qsh (those qsh pair added), numbered; qshd keys --remove N (or a fingerprint) removes one, for a lost or retired device; a key on several lines, or with options, is removed from all of them. Sessions already open with it go on until they end. Keys in ~/.ssh/authorized_keys are not part of this list (qshd reads them only with use_ssh_authorized_keys).

One-time codes (TOTP). As the user on the server, run qshd totp. It shows a QR code for any authenticator app and turns codes on once you type one back. From then on, logins ask for a code after the key, and each code works only once, also across several qshd of the same user (another port, a user-mode qshd next to the system one). qshd totp --disable turns them off. With totp = "required", accounts without codes cannot log in. Resuming a dropped session does not ask again. Right after qshd starts, codes that the previous process might have accepted are refused (up to a minute and a half), so a code seen before a restart cannot be replayed.

PAM. A qshd built with --features pam (see From source) can use PAM, like sshd's UsePAM: set use_pam = true and install a service file as /etc/pam.d/qshd (contrib/qshd.pam is one for Debian and Ubuntu; elsewhere, start from the system's /etc/pam.d/sshd; pam_service names another file). Then:

  • every login, with a key too, must pass PAM's account check (pam_nologin, pam_access, pam_time, expired accounts); a refused one gets "access denied" and the reason goes to the log. A password that must be changed (passwd -e, chage -d 0) refuses the login with a key too, as in sshd, since qsh cannot change it; change it first;
  • with password_authentication, passwords are checked by PAM (pam_authenticate) instead of /etc/shadow, so LDAP, SSSD and other modules work; their questions go to the client (their other messages only to the log, as they can tell which accounts exist), a module that changes the user name fails the login, and an expired password is refused, as qshd cannot have it changed;
  • in system mode, each session's program (a shell, a command, a subsystem) runs in a PAM session opened as root before qshd switches to the user, so pam_limits, pam_env, pam_loginuid and pam_systemd (a logind session, loginctl, XDG_RUNTIME_DIR) apply. Variables the modules set (pam_env, XDG_RUNTIME_DIR) may replace the built-in PATH but never what the server or the client sets (set_env, SSH_*, an accepted LANG). A small process stays as root beside the program to close the session when it ends; it writes no core file, and a program that ignores the hangup is killed after a second so the session still gets closed. With PAM, session_scope is not used: pam_systemd places the session. File copies and forwarded connections run without a PAM session.

PAM's authentication and the session have separate PAM handles (the session's is in the process that starts the program), so credentials that a module sets while authenticating (a Kerberos ticket) do not reach the session. pam_motd and pam_lastlog are not needed: qshd shows those itself.

Logs go to stderr (journald). Set the level with QSHD_LOG, for example QSHD_LOG=qsh=debug.

Benchmarks

Compared with OpenSSH 10 (ssh/scp with default settings). The network is emulated with tc netem on loopback inside a separate network namespace (MTU 1500). Both sides run on the same machine.

Connect and run true, ms, lower is better: ssh 87 / 631 / 1183 / 1000, qsh over QUIC 37 / 188 / 343 / 309, over TCP 15 / 217 / 420 / 337 (loopback, RTT 50 ms, RTT 100 ms with 1% loss, real server). File transfer, Mbit/s, higher is better: scp 66.2 / 10.4 / 53 / 53, qsh cp over QUIC 85.2 / 16.3 / 70 / 107, over TCP 79.2 / 14.1 / 107 / 94 (upload RTT 50 ms, upload RTT 100 ms with 1% loss, upload and download over the internet). Memory, RSS in MB, lower is better: OpenSSH 8.6 / 23 / 11-13 / 11, qsh 7.5 / 3-5 / 9 / 17 (server idle, server per session, client in a session, client sending 1 GiB).
All numbers

Connect and run true (median of 10 runs):

Network ssh qsh (QUIC) qsh (TCP fallback)
loopback, no delay 87 ms 37 ms 15 ms
RTT 50 ms, 100 Mbit/s 631 ms 188 ms 217 ms
RTT 100 ms, 1% loss, 20 Mbit/s 1183 ms (worst 1750) 343 ms (worst 345) 420 ms (worst 1551)

File upload (scp vs qsh cp, median of 3 runs):

Network Size scp qsh (QUIC) qsh (TCP fallback)
loopback, no delay 200 MiB 5.8 Gbit/s 5.2 Gbit/s 16.8 Gbit/s
RTT 50 ms, 100 Mbit/s 50 MiB 66.2 Mbit/s 85.2 Mbit/s 79.2 Mbit/s
RTT 100 ms, 1% loss, 20 Mbit/s 10 MiB 10.4 Mbit/s 16.3 Mbit/s 14.1 Mbit/s

Real server over the internet (median of 15 runs; transfers: 20 MiB, median of 3):

Connect + true Upload Download
ssh / scp 1000 ms 53 Mbit/s 53 Mbit/s
qsh (QUIC) 309 ms 70 Mbit/s 107 Mbit/s
qsh (TCP fallback) 337 ms 107 Mbit/s 94 Mbit/s

Memory (RSS, OpenSSH 10.5 vs qsh; one session running a command):

ssh / sshd qsh / qshd
Server, idle 8.6 MB 7.5 MB
Server, extra per session +23 MB +3–5 MB
Client during a session 11–13 MB 9 MB
Client, peak while sending 1 GiB 11 MB 17 MB

sshd starts separate processes for each connection; qshd serves all sessions in one process. The per-session figures include the remote command itself (about 1–2 MB).

Takeaways:

  • Connecting is 3–3.4× faster than ssh on any link with noticeable latency. QUIC combines the transport and TLS handshakes into 1 RTT, while ssh spends several RTTs on version exchange, key exchange and authentication.
  • Under packet loss, QUIC with BBR uses almost the whole link (16.3 of 20 Mbit/s), while scp gets about half.
  • On loopback, QUIC is CPU-bound (encryption and UDP in userspace), so TCP is faster there. On real links the network, not the CPU, is the bottleneck.

To reproduce (needs only util-linux, iproute2 and OpenSSH; no root):

cargo build --release
python3 bench/bench.py
python3 bench/charts.py   # redraw the charts in assets/ (the numbers are in charts.py)

Security

  • Encryption is TLS 1.3 only (rustls with ring), over both QUIC and TCP. There is no custom cryptography.
  • Post-quantum key exchange (from 2.0): the session keys come from X25519MLKEM768, which is X25519 together with ML-KEM-768 (FIPS 203; the libcrux-ml-kem crate, written in Rust). Traffic recorded today stays private unless both are broken, so a quantum computer built later does not open it. Both sides need 2.0 or newer: with an older one the connection uses X25519 alone, and qsh warns about it (qsh -v and qsh doctor name the key exchange). RequirePostQuantum yes in ~/.config/qsh/config (or -o) makes qsh refuse older servers, and require_post_quantum = true in qshd's config keeps older clients out. Logging in still uses Ed25519 signatures: those cannot be broken afterwards from a recording, only by a quantum computer present during the connection.
  • The server presents a self-signed certificate carrying its Ed25519 key. The client checks that key against known_hosts (TOFU, like ssh). If the key changes (or is revoked, or its host certificate is invalid), the handshake is broken off before the client shows its own key, so an impostor does not even learn who is connecting.
  • The client logs in with mutual TLS using its Ed25519 key, or after the handshake with a signature by any SSH key or certificate over data bound to the TLS session. Either way, the login cannot be relayed to another connection. To a host it does not know yet, the client shows its key only after the host is accepted (the handshake uses a throwaway key). Private key files that other users can read are refused, as by OpenSSH. Passwords are off unless the server sets password_authentication (system mode on Linux; yescrypt and SHA-crypt hashes from /etc/shadow, checked after the host key is verified, with the same work for unknown users). A second factor (TOTP) can be added.
  • Pairing uses SPAKE2 over the code plus key confirmation bound to the TLS session (exporter) and both keys. A man in the middle can neither brute-force the code offline nor relay the proof. The code pairs one device, allows 3 attempts (a typo does not waste it, and someone who only knows the user name must fail 3 logins to waste it) and expires after 10 minutes.
  • Privileges: in system mode, user processes run with the user's uid, gid and groups. File operations (cp, writing authorized_keys during pairing) are done by a qshd helper process running as the user, so root never opens paths the user controls. Forwarded connections (-L, -D) are opened by such a helper too and handed to qshd, so firewall rules by user (iptables --uid-owner) apply. Like sshd, file transfers and subsystems (sftp) start through the user's login shell, so nologin or git-shell also block them. authorized_keys and the directories leading to it are checked following sshd's StrictModes rules, along the real path (a symlinked ~/.ssh is checked where it really is).
  • Resource limits: handshake and hello timeouts, a limit on unauthenticated connections in total and per IP (like MaxStartups), connection and stream limits, 60 s idle timeout (on the TCP fallback, TCP keepalive, and a minute's limit on unacknowledged data). Before login a connection may open few streams and the server buffers at most about 1 MiB for it. User lookups and key files are read off the threads that drive the network, and helpers never hold a pipe that qshd reads locked.
  • No inherited descriptors: like sshd's closefrom, a user's program gets nothing from qshd but stdin, stdout and stderr (no other session's terminal, even for a moment).
  • Directory copy (cp -r) unpacks only regular files and directories. Absolute paths, .., links and device files are refused, and setuid/setgid bits are dropped, so a malicious server cannot write outside the target directory. Long-name and PAX headers over 64 KiB are refused before they are read, so it cannot fill the client's memory either.
  • Port forwarding in system mode connects and listens (-R) as the user, not as root, so firewall rules based on uid and the kernel's limits on ports apply. Accounts whose expiry date has passed (chage -E, usermod -e) are refused. As with sshd on most Linux systems (with PAM), a locked password (passwd -l, usermod -L) does not stop logins with a key: many accounts that log in only with keys have no password set either. To shut an account out, use usermod --expiredate 1 NAME or deny_users. With use_pam = false, /etc/nologin keeps everyone but root out and its text is shown, as in sshd.
  • Disconnects: a command without a terminal is stopped when its client goes away: its whole process group gets SIGHUP, then SIGKILL after 2 s. Unlike ssh, it does not keep running unattended. A terminal session is kept for session_timeout so the client can resume it; only a client of the same user that holds the session's 128-bit token can do that. On SIGINT/SIGTERM/SIGHUP the client ends the session and closes the connection cleanly.
  • Memory safety: qsh and qshd contain no unsafe code (#![forbid(unsafe_code)]). As root, qshd switches users in a small helper process (qshd internal-become) that sets the groups, group and user and then runs the user's program.
  • Agent forwarding uses a socket in a fresh private directory owned by the user. Connections from other users are refused (checked with SO_PEERCRED). The socket is removed when the client disconnects.

All OpenSSH security advisories since 2006 have been checked against qsh. Each one is either not applicable, covered by a test that reproduces the attack, or fixed; see docs/openssh-cve-review.md. Dependencies are checked with cargo audit in CI.

This is still a young project and has not had an external audit. For critical systems, keep regular ssh as a fallback way in.

Limitations

  • PAM and systemd-logind sessions only in builds with the pam feature and use_pam (see PAM); the release binaries have no PAM (for pam_access use allow_users/allow_groups), and loginctl does not show their logins. Without them, sessions still get XDG_RUNTIME_DIR and the session bus when /run/user/UID exists (another login of the user, or loginctl enable-linger), so systemctl --user works. 2FA is built in (TOTP). In system mode, terminal sessions are recorded in utmp, wtmp and lastlog where those files exist (who, last); systems that moved to wtmpdb do not see them.
  • Security keys only through ssh-agent; no PKCS#11 in qsh itself (use the agent for that too).
  • As with scp and sftp, a shell startup file that prints text for non-interactive shells (e.g. ~/.zshenv) breaks qsh cp.
  • -J works only when every hop runs qshd (for other hops, use ProxyCommand ssh -W %h:%p bastion in ~/.config/qsh/config to reach qshd's TCP port); with --full, hosts with ssh's ProxyJump/ProxyCommand are handed to ssh.
  • No GSSAPI/Kerberos, PKCS#11 or FIDO keys without an agent, UpdateHostKeys, VerifyHostKeyDNS or CheckHostIP (qshd has one host key, and known_hosts entries are per name).
  • qshd on Windows is new; it serves only the user it runs as, without X11 forwarding (see Windows above).

Upgrading

qsh update installs the latest release. Update qshd first when the notes say so.

Older versions

qsh and qshd 1.0.5 work with older versions of each other. With both at 1.0.5, a connection over TCP may have up to 512 streams each way (96 before), and ^C takes effect on the screen quickly (see above).

What v1.0 added on the protocol (banner, passwords, Unix sockets, X11, tunnels) needs qshd 1.0 on the server; with an older qshd, qsh reports that the feature is not supported and the rest works. qsh 0.5 works with qshd 0.4 and newer. Keys other than the Ed25519 TLS key, agent forwarding, one-time codes, host certificates and persistent sessions need qshd 0.5. qsh 0.4 and 0.5 need at least qshd 0.4: older servers reject them with "unsupported protocol version", so update qshd first. qshd 0.5 still accepts older clients.

Development

cargo test                        # unit tests and end-to-end tests (real qshd/qsh on loopback)
tests/system-mode.sh              # system mode (qshd as root): real root via sudo, or a user namespace without it
cargo clippy --all-targets -- -D warnings
QSH_FUZZ_ITERS=200000 cargo test --release --test fuzz   # longer run of the mutation tests
cargo +nightly fuzz run tar_extract   # coverage-guided fuzzing (cargo-fuzz; targets in fuzz/)
python3 bench/bench.py            # benchmark against OpenSSH

To cut a release, push a vX.Y.Z tag. GitHub Actions builds static binaries and publishes the release.

License

GPL-3.0

About

Fast SSH replacement over QUIC (UDP) with automatic TCP fallback. Sessions survive network drops, like mosh. Same options as ssh, so scp, sftp, rsync and git work over it. Port forwarding, file copy, OpenSSH keys and certificates.

Topics

Resources

Stars

11 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages