Carry your YubiKey anywhere, and every machine you SSH into signs and authenticates with it as if it were plugged in.
smartsocket is a small router that sits behind the standard gpg-agent and ssh-agent sockets. For every request it finds the key that can actually do the work, whether that's in the machine in front of you or forwarded from the one you're holding, and sends the request there. Your tools never know it exists.
New to YubiKeys? Start with the YubiKey Setup Guide. It takes you from a blank key to signing and authenticating, then hands back here for forwarding.
- Your key follows you. SSH into your desktop from a laptop, and commits you make there are signed by the key in your hand.
- Or it stays put. Sit at the desk with the key plugged in, and everything works locally, session or no session.
- Two keys, no thought. A forwarded key wins. Pull it, and the key in the machine takes over on the very next request.
- It routes on keys, not sockets. It asks each agent whether it can actually sign. An empty forward never hijacks you.
- PIN prompts land on your screen. When the server's own card needs a PIN, your laptop's native dialog asks for it.
- It's a drop-in. It owns the standard socket paths, so ssh, git and gpg need no changes and no per-host config.
- One router for both. GPG signing and SSH authentication go through the same logic.
Forwarding a hardware key has always meant picking one of two half-solutions:
- ssh-agent-switcher gives you a stable socket path that proxies to whichever forwarded agent is live. It's great for surviving tmux, but it's SSH-only and can't tell whether the key behind the socket can do anything.
- The gpg-agent forwarding recipe (
RemoteForward … S.gpg-agent.extraplusStreamLocalBindUnlink yes) handles GPG signing, but it's a hand-rolled setup, and a remote gpg-agent will happily autostart and steal your forwarded socket.
smartsocket combines the stable path with GPG forwarding, then adds the two things neither has: routing on whether a usable key is present, and automatic local fallback, with PIN prompts sent to your own screen.
| smartsocket | ssh-agent-switcher | manual gpg-agent forward | 1Password SSH agent | |
|---|---|---|---|---|
| SSH auth routing | ✅ | ✅ | ✅ | ✅ |
| GPG / Assuan signing | ✅ | ❌ SSH only | ✅ | ❌ SSH only |
| Routes on key presence (not just an open socket) | ✅ | ❌ first socket that opens | ❌ whatever's forwarded | |
| Automatic local fallback when the remote is keyless | ✅ | ❌ | ❌ manual | ❌ |
| Dual-key precedence (remote › local) | ✅ | ❌ | ❌ | via ssh-config conditionals |
| Pinentry forwarded to the client's native prompt | ✅ pinentry-smart |
❌ | ❌ | ✅ (app-native) |
Survives tmux / stale SSH_AUTH_SOCK |
✅ | ✅ | ❌ | ✅ |
| Transparent — no per-host config | ✅ systemd socket activation | ❌ fiddly per-host | ||
| Open source | ✅ Go | ✅ Go | ✅ built-in tooling | ❌ commercial |
Comparison reflects each tool's primary design goal; the adjacent projects
are excellent at what they set out to do — smartsocket just targets a
different sweet spot.
- On the server, the machine you SSH into:
make install enable. - On the client, the machine you SSH from: forward both agent sockets in
~/.ssh/config(details). - On the server, point
SSH_AUTH_SOCKat/run/user/1000/gnupg/S.gpg-agent.ssh(details).
That's the whole setup. To have the server's own PIN prompts appear on your laptop too, add pinentry forwarding.
Everything that needs your key goes through two sockets: the Assuan socket (S.gpg-agent) for signing and decryption, and the ssh-agent socket (S.gpg-agent.ssh) for authentication. smartsocket owns both and backs them with whichever YubiKey is usable right now.
flowchart LR
u1["git commit -S<br/>(sign)"] --> gpg
u2["gpg --decrypt<br/>(decrypt)"] --> gpg
u3["gpg --sign / --encrypt"] --> gpg
u4["ssh · scp · git push<br/>(auth)"] --> ssh
gpg["S.gpg-agent<br/>Assuan protocol"] --> smart(("smartsocket"))
ssh["S.gpg-agent.ssh<br/>ssh-agent protocol"] --> smart
smart --> key["🔑 whichever YubiKey<br/>is usable — local or remote"]
classDef router fill:#cfe8ff,stroke:#0969da,stroke-width:2px,color:#082b52;
classDef sock fill:#efe6ff,stroke:#8250df,color:#2a1152;
classDef key fill:#fff3bf,stroke:#bf8700,color:#3d2f00;
class smart router;
class gpg,ssh sock;
class key key;
For each connection it asks one question: does the forwarded agent hold a usable key? For SSH, that means the agent offers at least one identity. For GPG, it means the agent can reach a card. If yes, the request goes to the remote. Otherwise, including on any error or timeout, it goes to the local agent. The internals are in ARCHITECTURE.md.
In the diagrams, green is the path that lights up, grey is dormant, and 🔑 amber is a key that's physically present.
At the desk. No session, so nothing is forwarded. The probe finds nothing and the local agent signs with the key in the machine.
flowchart LR
t["tools on server"] --> s(("smart"))
s -.->|"remote empty"| r["remote"]
s ==>|"routes local"| l["local gpg-agent"]
l --> ks["🔑 server key"]
kc["client key — none"]
classDef on fill:#d7f5dd,stroke:#1a7f37,stroke-width:2px,color:#08260f;
classDef off fill:#ececec,stroke:#b0b0b0,color:#6b6b6b;
classDef key fill:#fff3bf,stroke:#bf8700,color:#3d2f00;
class t,s,l on;
class r,kc off;
class ks key;
Away, one key. The key rides your SSH session onto the server. The probe sees it and routes remote. The server needs no key of its own, and the same key still works locally on the laptop.
flowchart LR
kc["🔑 client key"] ==>|"SSH forward"| r["remote"]
t["tools on server"] --> s(("smart"))
s ==>|"remote has key"| r
s -.->|"local: no card"| l["local gpg-agent"]
ks["server key — none"]
classDef on fill:#d7f5dd,stroke:#1a7f37,stroke-width:2px,color:#08260f;
classDef off fill:#ececec,stroke:#b0b0b0,color:#6b6b6b;
classDef key fill:#fff3bf,stroke:#bf8700,color:#3d2f00;
class t,s,r on;
class l,ks off;
class kc key;
Away, two keys. A duplicate key stays in the server. The forwarded key wins by precedence and the server's key waits on standby. Pull the client key, even while the session lingers, and the next request falls back to the server's key without a hitch.
flowchart LR
kc["🔑 client key"] ==>|"SSH forward"| r["remote"]
t["tools on server"] --> s(("smart"))
s ==>|"remote wins (precedence)"| r
s -.->|"standby"| l["local gpg-agent"]
l -.- ks["🔑 server key (idle)"]
classDef on fill:#d7f5dd,stroke:#1a7f37,stroke-width:2px,color:#08260f;
classDef off fill:#ececec,stroke:#b0b0b0,color:#6b6b6b;
classDef key fill:#fff3bf,stroke:#bf8700,color:#3d2f00;
classDef idle fill:#fff8dd,stroke:#c9a200,color:#5a4a00,stroke-dasharray:4 3;
class t,s,r on;
class kc key;
class l off;
class ks idle;
No key anywhere. Nothing is forwarded and nothing is plugged in. The router still routes local, the local agent has no card, and the operation fails, as it should. Nothing is quietly handed to a keyless agent.
flowchart LR
t["tools on server"] --> s(("smart"))
s -.->|"remote empty"| r["remote"]
s ==>|"fails toward local"| l["local gpg-agent"]
l --> x["❌ no card —<br/>operation fails"]
kc["client key — none"]
ks["server key — none"]
classDef on fill:#d7f5dd,stroke:#1a7f37,stroke-width:2px,color:#08260f;
classDef off fill:#ececec,stroke:#b0b0b0,color:#6b6b6b;
classDef fail fill:#ffd7d5,stroke:#cf222e,color:#5a0a0a;
class t,s,l on;
class r,kc,ks off;
class x fail;
To force local while a keyed remote is connected, disconnect the session.
On the server:
make install
make enableThis builds and installs smartsocket and pinentry-smart to ~/.local/bin and the systemd user units to ~/.local/share/systemd/user. make enable masks the stock gpg-agent socket units and enables smartsocket's sockets and a dedicated local gpg-agent.
Standard paths, owned by smartsocket:
/run/user/1000/gnupg/S.gpg-agentfor GPG operations/run/user/1000/gnupg/S.gpg-agent.sshfor SSH authentication
Remote sockets, forwarded from the client over SSH:
/run/user/1000/gnupg/S.gpg-agent.remote/run/user/1000/gnupg/S.gpg-agent.ssh.remote
Local sockets, the local gpg-agent fallback:
/run/user/1000/gnupg/S.gpg-agent.local/run/user/1000/gnupg/S.gpg-agent.ssh.local
On the machine you SSH from, the one holding the YubiKey, run gpg-agent with SSH support:
# ~/.gnupg/gpg-agent.conf
enable-ssh-supportThen forward both agent sockets in ~/.ssh/config:
Host myserver
# Forward GPG agent socket (for signing)
RemoteForward /run/user/1000/gnupg/S.gpg-agent.remote /path/to/local/S.gpg-agent
# Forward SSH agent socket
RemoteForward /run/user/1000/gnupg/S.gpg-agent.ssh.remote /path/to/local/S.gpg-agent.ssh
# Allow SSH to overwrite stale sockets on reconnect
StreamLocalBindUnlink yes
To find your local socket paths:
# GPG socket gpgconf --list-dirs agent-socket # Linux: /run/user/1000/gnupg/S.gpg-agent # macOS: /Users/username/.gnupg/S.gpg-agent # SSH socket gpgconf --list-dirs agent-ssh-socket # Linux: /run/user/1000/gnupg/S.gpg-agent.ssh # macOS: /Users/username/.gnupg/S.gpg-agent.ssh
On the server, make sure /etc/ssh/sshd_config includes the following, so SSH can clean up stale forwarded sockets on reconnect:
StreamLocalBindUnlink yes
On the server, point SSH_AUTH_SOCK at the standard path:
# .bashrc / .zshrc export SSH_AUTH_SOCK=/run/user/1000/gnupg/S.gpg-agent.ssh
# config.nu $env.SSH_AUTH_SOCK = "/run/user/1000/gnupg/S.gpg-agent.ssh"
When the server's local key serves, because no remote is connected or the remote is keyless, gpg-agent needs that card's PIN. On a headless server the default curses pinentry is awkward, and an unattended agent can't use it at all. pinentry-smart sends the prompt to the client's native pinentry, such as pinentry-mac, over a reverse-forwarded socket. With no client connected, it falls back to a local pinentry. It rides your existing outbound SSH session, so the server never connects back to the client and stores no credential. How it decides safely is in ARCHITECTURE.md.
make install already put pinentry-smart in ~/.local/bin/.
On the server, point gpg-agent at it and reload. The path must be absolute: gpg-agent runs pinentry-program with no PATH search, so a bare pinentry-smart fails with can't connect to the PIN entry module …: IPC connect call failed or No pinentry.
# ~/.gnupg/gpg-agent.conf
pinentry-program /home/<you>/.local/bin/pinentry-smart
systemctl --user restart gpg-agent-local.service # re-read the configpinentry-smart forwards to the client only if /run/user/<uid>/gnupg/S.pinentry is a live pinentry, meaning the client is connected and its responder is up. Otherwise it runs the local fallback, /usr/bin/pinentry-curses by default. PINENTRY_SMART_SOCKET and PINENTRY_SMART_FALLBACK override both.
On the client, reverse-forward a pinentry socket to the server, alongside the agent forwards, under the server's Host block:
RemoteForward /run/user/1000/gnupg/S.pinentry /Users/<you>/.hamr/pinentry.sock
StreamLocalBindUnlink yes
Then run a small responder in your GUI login session, so the native dialog can draw. Test it from a GUI terminal first:
socat UNIX-LISTEN:$HOME/.hamr/pinentry.sock,fork,unlink-early EXEC:$(which pinentry-mac)
The SSH forward delivers to a socket, but pinentry-mac speaks Assuan on stdin and stdout. socat bridges the two: UNIX-LISTEN gives the forward a target, and EXEC starts a fresh pinentry-mac for each connection with the socket wired to its stdio. fork means one per PIN request. It runs silently; the popup is the output.
Once it works, make it permanent with a user LaunchAgent (~/Library/LaunchAgents/io.kingland.hamr.pinentry.plist, with RunAtLoad and KeepAlive, running the same socat command). It stays in the GUI session and survives reconnects and reboots.
With the session up, the server's PIN prompt pops up as your native pinentry. With it down, the server falls back to its local pinentry automatically, since StreamLocalBindUnlink removes the forwarded socket on disconnect.
make status # Check all socket and service status make disable # Stop smartsocket and restore original gpg-agent make enable # Enable smartsocket (masks original gpg-agent) make uninstall # Remove everything
For testing, or on systems without systemd, smartsocket can run on its own and listen on .smart sockets instead:
./smartsocket
Clients then have to be pointed at the .smart paths.
smartsocket-gpg.socketlistens onS.gpg-agent.smartsocket-ssh.socketlistens onS.gpg-agent.ssh.smartsocket.serviceis the router.gpg-agent-local.socketlistens onS.gpg-agent.local.gpg-agent-ssh-local.socketlistens onS.gpg-agent.ssh.local.gpg-agent-local.serviceis the local gpg-agent.
Symptom. Connections to S.gpg-agent or S.gpg-agent.ssh bypass smartsocket and reach a local gpg-agent instead. For example, ssh-add -L returns "no identities", or only the local key, when a remote key should be in play.
Check first. Run ss -lxn | grep S.gpg-agent. Two listeners on the same path mean a rogue agent stole it: smartsocket's has a backlog of 4096, the rogue's 64. A single listener means smartsocket is working and chose local on purpose, because the remote held no usable key or answered too slowly. In that case, check the remote.
Cause. Anything that starts gpg-agent --daemon replaces the socket file with its own: gpgconf --launch gpg-agent, or gpg-connect-agent without --no-autostart. The details are in ARCHITECTURE.md.
Recovery. Restart the socket units so they re-bind the paths:
pkill -f 'gpg-agent.*--daemon'
systemctl --user restart smartsocket-gpg.socket smartsocket-ssh.socketPrevention. Keep shell startup and SSH config from launching gpg-agent:
- Remove
gpgconf --launch gpg-agentfrom.bashrc,config.nuand the like. smartsocket andgpg-agent-local.serviceare socket-activated, so no launch is needed. - If
~/.ssh/confighas aMatch host * exec "gpg-connect-agent UPDATESTARTUPTTY /bye"block for pinentry-tty, add--no-autostart:Match host * exec "gpg-connect-agent --no-autostart UPDATESTARTUPTTY /bye"