Securing data with encryption

Encryption in daily use: SSH keys and the files they live in, agent forwarding and tunnels, and what GPG does with a key pair for files and signatures.

Lesson 3 of 3 in objective 110. Security, part of LPIC-1 Exam 102-500.

Two key files, on two different machines. Knowing which is which is the exam. authorized_keys — Lives on: The server; Holds: Public halves allowed to log in as you; Put there by: ssh-copy-id; A surprise there means: Somebody else can log in as you. known_hosts — Lives on: Your own client; Holds: Host keys you have accepted before; Put there by: ssh, on first connection; A surprise there means: A loud warning: the server is not the one you met authorized_keys known_hosts Lives on The server Your own client Holds Public halves allowed to log in as you Host keys you have accepted before Put there by ssh-copy-id ssh, on first connection A surprise there means Somebody else can log in as you A loud warning: the server is not the one you met
Two key files, on two different machines. Knowing which is which is the exam.

SSH, and the two sets of keys

A server has HOST keys in /etc/ssh, and they are what lets a client know it is talking to the same machine as last time; the client records what it saw in ~/.ssh/known_hosts, which is why replacing a server produces a loud warning about a changed key. A user has their OWN key pair, made with ssh-keygen: the private half stays in ~/.ssh/id_rsa or id_ed25519 and never leaves the machine, and the public half is copied into ~/.ssh/authorized_keys on the server — ssh-copy-id does exactly that.

Permissions are enforced rather than advisory, and this is where key-based login most often fails silently. sshd refuses to read a private key or an authorized_keys file that anyone else can get at, so the fix is always the same two commands: chmod 700 ~/.ssh and chmod 600 ~/.ssh/authorized_keys, with both owned by the user they belong to. A home directory that is group-writable will do it too. The refusal is not reported to the client — it simply falls back to asking for a password — so "the key is installed and it still prompts" is a permissions question every time, and the server's log is where it says so.

A passphrase on the private key means typing it each time, which ssh-agent solves by holding the decrypted key in memory for the session. ssh-add with no arguments loads the default keys from ~/.sshid_rsa, id_ecdsa, id_ed25519 — and ssh-add -l lists what the agent is holding. The agent is reached through the socket named in SSH_AUTH_SOCK, and agent forwarding lets a further hop use the same agent without the key ever being copied to the intermediate machine.

Beyond logins, ssh -L forwards a local port through the encrypted connection to somewhere the server can reach, and ssh -R does the reverse. That is the standard answer whenever a question describes reaching a service that is not exposed directly.

A password prompt is how an SSH permissions error presents itself. In order: Key installed, yet ssh asks for a password (a permissions question every time), then sshd refused to read a loose file (a private key or authorized_keys anyone else can reach; a group-writable home does it too), then The server log says so (the client is told nothing — it just falls back to the prompt), then chmod 700 ~/.ssh, 600 on the files (both owned by the user they belong to). Key installed, yet ssh asks for a password a permissions question every time sshd refused to read a loose file a private key or authorized_keys anyone else can reach; a group-writable home does it too The server log says so the client is told nothing — it just falls back to the prompt chmod 700 ~/.ssh, 600 on the files both owned by the user they belong to
A password prompt is how an SSH permissions error presents itself.

GPG

GPG uses the same public-key idea for files and messages. You encrypt with the recipient's PUBLIC key so that only their private key can open it, and you SIGN with your own private key so that anyone with your public key can verify it was you — those two directions are the thing to get straight, because every question here is built on candidates reversing them.

The commands: gpg --gen-key creates a pair, gpg --list-keys and --list-secret-keys show what you hold, gpg --export and --import move public keys about, and gpg --encrypt/--decrypt and --sign/--verify do the work. Keys live under ~/.gnupg. Note the name: the current release installs as both gpg and gpg2, and older systems that still shipped GnuPG 1.x kept gpg for it and used gpg2 for the newer one — so gpg2 and gpg are interchangeable in an answer unless the question is specifically about a machine with both.

Since GnuPG 2 the private keys are not handled by gpg itself. Every decryption and every signature goes through gpg-agent, which holds the unlocked key material and is why signing several files in a row asks for the passphrase only the first time. It expires a cached passphrase after default-cache-ttl seconds of disuse, up to max-cache-ttl, both set in ~/.gnupg/gpg-agent.conf, and the agent has to be told to re-read that file — gpgconf --reload gpg-agent. It is exactly the relationship ssh-agent has to the SSH client, and gpg-agent can take over that job too when configured with enable-ssh-support. Its two neighbours are worth naming so they are not mistaken for it: dirmngr is the component that does network access, such as keyserver lookups, and never sees a passphrase, and gpgconf inspects and restarts the components while storing no secrets of its own. Everything under ~/.gnupg, keyrings and the private key directory alike, should be mode 700 and owned by the user.

Revocation matters as much as generation, and it is the one thing that has to be done BEFORE you need it: once a private key is lost, nothing can be signed with it, including the statement that it should no longer be trusted. So a revocation certificate is generated at the same time as the key and kept somewhere safe. gpg --gen-revoke KEYID produces one — spelled --generate-revocation in current releases, with the short form still accepted — and -o writes it to a file. Publishing that certificate to a keyserver with gpg --send-keys is what withdraws the key in public.

Which half of whose key — the cross every GPG question is built on. A grid of Whose key against Which half. Yours: The public half gives Others verify your signature; The private half gives You sign with it. The recipient’s: The public half gives You encrypt to them; The private half gives Only they can open it. Which half → Whose key ↓ The public half The private half Yours Others verify your signature You sign with it The recipient’s You encrypt to them Only they can open it
Which half of whose key — the cross every GPG question is built on.
gpg --list-secret-keys --keyid-format shortsec   ed25519/A1B2C3D4 2026-08-03 [SC]uid   Alice Doe <alice@example.com>gpg2 --gen-revoke -o revoke.asc A1B2C3D4Create a revocation certificate for this key? (y/N) ystore revoke.asc somewhere the key is not
Making the certificate that withdraws a key, before it is needed.

Worth carrying in

ssh-keygen -t ed25519
Create a key pair. The private half never leaves the machine.
~/.ssh/authorized_keys
On the SERVER: public keys allowed to log in as this user.
~/.ssh/known_hosts
On the CLIENT: host keys seen before. A change is a loud warning.
ssh-copy-id user@host
Install your public key into the server's authorized_keys.
ssh-agent / ssh-add
Hold a decrypted private key for the session; -A forwards the agent. ssh-add alone loads the default keys.
chmod 700 ~/.ssh
With 600 on the private key and on authorized_keys. sshd refuses anything looser, silently.
ssh -L 8080:host:80
Tunnel a local port through the connection. -R is the reverse.
gpg --encrypt
With the recipient's public key. --sign uses your own private key. gpg2 is the same program.
gpg --gen-revoke
The certificate that withdraws a key. Made WITH the key, not after losing it.
gpg-agent
Holds the unlocked private key and caches the passphrase. default-cache-ttl in ~/.gnupg/gpg-agent.conf.
~/.gnupg
Where GPG keeps its keyrings. Mode 700, owned by the user.

What the exam does with this

Objective
110. Security
Share of the exam
16.67% (the whole objective)
Questions in this lesson
20
Signed for by a person
0

Partly checked. None of the 20 questions here has been read against the cited source by a person. 20 questions have been checked against their cited clause by an automated pass — which is not the same thing, and is not a signature.

Only questions a person has signed for are used in mock exams here. That is the whole difference between the two kinds of checking above.

How these questions are written — where each question comes from, what the verification ledger records, and what happens when one is found wrong.

Drill this lesson

A lesson is one sitting: the trainer draws a short run from these questions alone and spaces the ones you get wrong.

Practise Securing data with encryption

Questions in this lesson

Practise Securing data with encryption

The rest of objective 110