SSH Keys and Agents
Quick answer
A user key pair contains a private key that stays under your control and a public key that can be installed on an authorized server. An agent can sign authentication requests without repeatedly unlocking the key.
Prepare the practice environment
Run python3 lab-fixtures/ssh-transfer/setup.py from the extracted package root as an ordinary user. Enter the printed private path and check pwd. Use a fresh fixture and Bash with LC_ALL=C and pipefail. Only local rsync and synthetic files are tested here. For manual SSH examples use an isolated authorized VM network, snapshot, console access, provisioned learner account and independently verified host keys; see the lab guide. Never use real credentials or external hosts.
How it works
Use a separate lab key and a passphrase entered interactively, not as a command argument. Ed25519 is a common modern choice where policy permits. Keep the private key readable only by its owner. An agent holds usable identities and exposes a local socket; access to that socket is sensitive. Use a short lifetime and do not forward the agent by default. Server authorization depends on account policy, file permissions and configured authentication methods.
A passphrase protects a private key at rest, while an unlocked agent enables signing requests during its lifetime. A process with access to the agent socket may request signatures even if it cannot read the private key file. Treat the agent socket as sensitive, keep lab sessions short and remove lab identities after practice. File permissions alone do not prove that a key is authorized remotely.
Try the examples
This is ordinary placeholder text, not a usable credential. Mode 600 permits owner read/write.
Expected stdout:
600 mock-private.txtssh-keygen -t ed25519 -f ./lab_ed25519 -C bytemind-labVM only; enter a passphrase at the prompt. Abort if the path already exists. The .pub file may be shared; never share the private file.
Manual example; not executed locally. Follow its stated environment restrictions.
ssh-agent bash --noprofile --norc -c 'ssh-add -t 300 ./lab_ed25519 && ssh-add -l'VM only after generating the lab key. This agent is tied to the child command, and the identity lifetime is five minutes.
Manual example; not executed locally. Follow its stated environment restrictions.
Common mistakes
Never copy the private key to the server, include it in a repository, or leave agent forwarding enabled unnecessarily. ssh-copy-id changes the remote authorized key list and requires existing authorized access.
Practice
In an isolated VM, generate a unique passphrase-protected key, record its public fingerprint, and explain how to revoke only that lab key from the server with console access.
Related references
Study: ssh-keygen, ssh-agent, ssh-add, ssh-copy-id. These are reference names, not deployed links.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
SSH keys and agents — Knowledge Check
Apply SSH trust and transfer concepts to synthetic fixtures and VM-only scenarios.
Which file may be shared?
What is an agent used for?
What does ssh-add -t 300 request?
What does ssh-copy-id change?