brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: ssh-keygen -s signs SSH user certificates so servers trust one CA

Network and access
~/tips/tip-ssh-keygen-user-certificates

ssh-keygen -s user_ca -I alice-laptop -n alice -V +52w id_ed25519.pub

Sign user keys with a CA so servers stop needing every public key in authorized_keys.

With more than a few servers, copying public keys around gets old. SSH certificates turn it around: servers trust one CA key, and you sign the user keys.

Create a CA key once and keep it somewhere safe. Then sign a user’s public key:

ssh-keygen -t ed25519 -f user_ca
ssh-keygen -s user_ca -I alice-laptop -n alice -V +52w id_ed25519.pub

-I is the key ID that shows up in the server logs, -n the login names this certificate is valid for, and -V +52w makes it expire in a year. The result is id_ed25519-cert.pub next to the key, and ssh picks it up by itself.

On each server, one line in sshd_config makes it trust the CA:

TrustedUserCAKeys /etc/ssh/user_ca.pub

To check what you signed, ssh-keygen -L -f id_ed25519-cert.pub prints the principals, validity and extensions. I like that output when something does not work, because a typo in -n is the usual suspect. The man page notes a certificate without principals is refused for login.

The CA private key is now the key to every server, so treat it that way: a passphrase, offline storage, and short validity periods on what you sign.

Further reading: ssh-keygen man page, CERTIFICATES, sshd_config man page

More Network and access tips scp -3 alice@server-a:/var/backups/db.sql.gz bob@server-b:/srv/restore/ tailscale exit-node suggest tailscale lock sign nodekey:1abddef1 tlpub:abcdef12 wg genpsk > peer1.psk Table = off All Network and access tips (163) All topics

Link