Dit deel is nog niet vertaald. Je ziet de Engelse tekst.
Wat het doet
A key with a passphrase is safe on disk, but typing the passphrase for every connection is slow. ssh-agent is a small background program that holds the unlocked keys in memory. ssh asks the agent to sign the login; the private key never leaves the agent.
ssh-add loads keys into the agent (asking for the passphrase once), lists them and removes them. On a desktop, the agent usually starts with your session; in a plain terminal you start it with eval "$(ssh-agent)".
Zo schrijf je het
ssh-agent [-c | -s] [-Dd] [-a BIND_ADDRESS] [-E HASH] [-O OPTION] [-P PROVIDERS] [-t LIFE] [COMMAND [ARG ...]]
ssh-agent [-c | -s] -k
ssh-add [-cCDdKkLlqvXx] [-E HASH] [-H HOSTKEY_FILE] [-h DEST] [-S PROVIDER] [-t LIFE] [FILE ...]
ssh-add -s PKCS11 / ssh-add -e PKCS11 / ssh-add -T PUBKEY ...Opties 30
Meest gebruikt
ssh-agent
ssh-add
Niets past bij dit filter.
Voorbeelden 12
$ als gewone gebruiker# als root (of met sudo)
1Start an agent in your shell
eval "$(ssh-agent -s)" Agent pid 4321Sets SSH_AUTH_SOCK and SSH_AGENT_PID for this shell.
2Load your key (type the passphrase once)
ssh-addEvery ssh in this session now uses the key without asking.
3List the keys in the agent
ssh-add -l 256 SHA256:Xh7… student@server1 (ED25519)"The agent has no identities" = nothing loaded yet.
4Load a key for one hour only
ssh-add -t 1h ~/.ssh/prod_adminAfter an hour the key is removed automatically. Good for production keys.
5Remove all keys when you leave your desk
ssh-add -DNobody can use your keys from this session any more.
6Ask before each use of a key
ssh-add -c ~/.ssh/prod_adminA confirmation window appears for each use (needs a graphical askpass program).
7Lock the agent with a password
ssh-add -xKeys stay loaded but cannot be used until
ssh-add -X.8Use the agent on a jump host safely (forward only when needed)
ssh -J admin@bastion admin@10.10.0.15With -J the key stays on your computer; prefer it to agent forwarding (-A).
9Start a command with its own agent
ssh-agent bash -c 'ssh-add ~/.ssh/deploy_key && ./deploy.sh'The agent and the key disappear when the command ends.
10Stop the agent
eval "$(ssh-agent -k)"Kills the agent and clears the variables.
11Limit a key to some servers
ssh-add -h server2.example.com ~/.ssh/id_ed25519The agent refuses to use this key for any other destination.
12Check that the agent is reachable
echo "$SSH_AUTH_SOCK"Empty means no agent is connected to this shell.
Niets past bij dit filter.
Let op
- Agent forwarding (
ssh -A) lets root on the remote server use your keys while you are connected. Avoid it on servers you do not fully trust. - An agent started in one terminal is not known in another terminal unless you export SSH_AUTH_SOCK there.
Bestanden
$SSH_AUTH_SOCK- The socket where programs talk to the agent.
Tips om te onthouden
eval "$(ssh-agent)"→ssh-add→ work →ssh-add -D.