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: expiry-time in authorized_keys makes an SSH key stop working on a date

Network and access
~/tips/tip-ssh-authorized-keys-expiry-time

expiry-time="20270131" ssh-ed25519 AAAAC3Nza... guest@example

Give a temporary key a built-in end date so nobody has to remember to remove it.

Temporary access has a habit of becoming permanent. For a key that belongs to a contractor or a short project, I like the end date on the key line itself.

The option goes in front of the key in ~/.ssh/authorized_keys:

expiry-time="20270131" ssh-ed25519 AAAAC3Nza... guest@example

From that moment sshd refuses the key. The format is YYYYMMDD or YYYYMMDDHHMM, with optional seconds. The man page says the time is read in the server’s time zone, unless you add a Z at the end for UTC:

expiry-time="202701311700Z" ssh-ed25519 AAAAC3Nza... guest@example

You can combine it with other options, separated by commas, for instance with from= to also limit where the key may log in from.

Keep in mind the line stays in the file after it expires. It does nothing anymore, but cleaning those up now and then keeps the file honest about who really has access. And this only covers the key. If that person also has a password or another key on the account, expiry-time does not touch those.

Further reading: sshd man page, AUTHORIZED_KEYS FILE FORMAT

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