What do OpenSSH ssh-add's -t, -c and -x options each limit about agent-held keys, and what does each leave exposed?
answer
- when, not who
- a timer, a prompt, a padlock
- ssh-askpass exit status
- certificates expire out since 10.1
basics
~20 sssh-add -t deletes a key after a lifetime, -c makes each use wait for an ssh-askpass confirmation, and -x locks the whole agent until -X. Each narrows when keys can be used, not who may ask or where.
solid answer
~40 s`ssh-add -t 8h` (or `ssh-agent -t` as a default) sets a lifetime; the agent deletes the key when it runs out, but within the window anyone who reaches the socket can still use it. `ssh-add -c` marks a key so that every signature waits for a confirmation through `ssh-askpass`; the prompt shows the key and fingerprint rather than where the request came from, so a well-timed request gets approved. `ssh-add -x` locks the agent with a password: while locked it lists no keys and refuses to sign, until `ssh-add -X`. Since OpenSSH 10.1 `ssh-add` also gives a loaded certificate a lifetime of its expiry plus a five-minute grace, which `-N` switches off. None of these says which hosts a key may reach; that is what `-h` destination constraints are for.
code
bash · 5 linesssh-add -t 8h ~/.ssh/id_ed25519 # deleted from the agent after 8 hours
ssh-add -c -t 1h ~/.ssh/prod_ed25519 # every use needs ssh-askpass approval; gone in 1 hour
ssh-add -x # lock: listing shows nothing, signing refused
ssh-add -X # unlock with the same password
ssh-add -N ~/.ssh/id_ed25519 # load key and its -cert.pub with no expiry-based lifetimego deeper
Recall the three: -t for a lifetime, -c for a confirmation on every use, -x and -X to lock and unlock the agent.
Explain what each leaves open: use inside the lifetime, approvals of mistimed requests, and full access whenever the agent is unlocked.
Combine them sensibly for production keys, know the 10.1 certificate lifetime and -N, and say why none restricts destinations.
Weigh prompts and timers against user friction, and decide when to stop tuning these and move to short-lived certificates or no forwarding.
## Three controls, one agent By default `ssh-agent` keeps every key until it is removed or the agent exits, signs for any client that reaches its socket and asks nobody. `ssh-add` offers three ways to narrow that, and they are often confused. | Option | What it does | Also settable via | What it leaves open | |---|---|---|---| | `-t life` | deletes the key after `life` | `ssh-agent -t`, `AddKeysToAgent <interval>` | free use until the timer runs out | | `-c` | each use waits for a confirmation | `AddKeysToAgent confirm` | approvals given to the wrong request | | `-x` / `-X` | locks / unlocks the whole agent | none | everything while unlocked | ## Lifetimes: -t **`ssh-add -t`** takes seconds or the time format from the server configuration manual (`30m`, `8h`, `1h30m`). When the lifetime expires the agent deletes the key, and the next login asks for the passphrase again. `ssh-agent -t` sets a default for every key added later, and a value given to `ssh-add` overrides it. Without either, the manual is plain: "the default maximum lifetime is forever". The client directive `AddKeysToAgent` can also take an interval, so keys loaded on first use get a lifetime automatically. What a lifetime does not do: - **limit use inside the window**: if the agent is forwarded somewhere hostile at 09:00 and the key lives until 17:00, the whole day is exposed; - **touch the key file**: the encrypted file on disk is unaffected, and loading it again starts a fresh lifetime; - **apply retroactively**: keys already in the agent keep whatever lifetime, or lack of one, they were added with, because loaded keys are immutable. **Certificates since OpenSSH 10.1.** When `ssh-add` loads a user certificate it now asks the agent to delete it shortly after the certificate expires, the expiry plus a five-minute grace, so stale certificates no longer sit in agents. `ssh-add -N` suppresses that and sets no lifetime for the certificate. ## Confirmation: -c **`ssh-add -c`** marks a key so that every signing request triggers `ssh-askpass` on the machine running the agent. Approval is signalled by `ssh-askpass` exiting with status zero, not by anything typed. `AddKeysToAgent confirm` does the same for keys loaded on first use. Its limits: - the dialog shows the key's comment and fingerprint, not which host or forwarding path the request came through; - an attacker who can see when you connect can time a request to coincide with your own login, and you approve it; - it needs a working askpass program and a display, which servers and headless sessions often lack. OpenSSH's own write-up on agent restriction describes confirmation as "somewhat easy to phish" for exactly these reasons. ## Locking: -x and -X **`ssh-add -x`** prompts for a password and locks the agent. While locked, the agent answers a request to list keys with an empty list and refuses signing and most other operations; `ssh-add -X` with the same password unlocks it. Keys stay loaded throughout, so unlocking needs no passphrases. Locking is the tool for stepping away: before leaving a session idle, lock the agent rather than killing it. Its properties in short: - the password is chosen at lock time and is unrelated to any key passphrase; - a forwarded copy of the agent is locked too, because it is the same agent behind a relayed socket; - it protects nothing while unlocked. One interaction was fixed in **OpenSSH 10.5**: a locked agent used to refuse the binding requests that identify forwarded connections, which let operations meant for local use only be performed remotely; it now accepts them while locked. Related: since **OpenSSH 10.0**, sending `SIGUSR1` to `ssh-agent` deletes every loaded key, which works even when you can no longer reach its socket. ## Combining them 1. Give every key a lifetime that matches a working day or less. 2. Add `-c` to keys that open production, accepting the prompt as a speed bump rather than a guarantee. 3. Lock the agent whenever the session is unattended. 4. For anything forwarded, rely on destination constraints (`ssh-add -h`) or avoid forwarding, because none of these three controls asks *where* a signature is going.
- What changed for user certificates loaded into an agent in OpenSSH 10.1?`ssh-add` now asks the agent to delete a certificate shortly after it expires, its expiry plus a five-minute grace, so expired certificates stop cluttering the agent and being offered to servers. `ssh-add -N` disables this and leaves the certificate without a lifetime. Before 10.1 a certificate stayed until removed or until a `-t` lifetime ran out.
- How do you empty an agent whose socket you can no longer reach?Since OpenSSH 10.0, send it `SIGUSR1`, for example `kill -USR1 "$SSH_AGENT_PID"`: the agent deletes every loaded key without anyone connecting to its socket. `ssh-agent -k` instead terminates the agent entirely.
- ssh-add -t sets how long the passphrase is cached by the shell.
- The -c confirmation prompt tells you which host the request came through.
- A locked agent keeps signing for sessions that were already connected.
- ssh-add -x re-encrypts the key files on disk with a new password.
- ssh-agent removes keys after one hour unless told otherwise.
Assumes OpenSSH 10.5; since 10.1 ssh-add gives certificates an agent lifetime of their expiry plus a 5-minute grace (-N disables it), since 10.0 SIGUSR1 makes ssh-agent drop all keys, and 10.5 fixed locked agents refusing session-bind requests.