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.
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 ~/.ssh — id_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.
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.
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
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;
-Aforwards the agent.ssh-addalone loads the default keys. - chmod 700 ~/.ssh
- With 600 on the private key and on
authorized_keys.sshdrefuses 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.
--signuses your own private key.gpg2is 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-ttlin~/.gnupg/gpg-agent.conf. - ~/.gnupg
- Where GPG keeps its keyrings. Mode 700, owned by the user.
What the exam does with this
- Encrypt with the recipient's PUBLIC key; sign with your OWN PRIVATE key. Reversing these is the standard distractor.
authorized_keysis on the server andknown_hostsis on the client. Know which is which.- SSH refuses over-permissive key files —
chmod 700 ~/.sshand 600 on a private key. The symptom is a password prompt, not an error. - A revocation certificate has to exist before the key is lost. That is the whole question.
- 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
- Your SSH agent is running and you want to see the fingerprints of the identities it is currently holding in memory. Type the complete command. machine-checked
- You generated an SSH key pair on your laptop and want passwordless logins to the server web01. Which file has to change, and on which machine? machine-checked
- Key-based login to web01 fails and the server's log records: `Authentication refused: bad ownership or modes for directory /home/dev/.ssh`. Which fix is the right one? machine-checked
- A PostgreSQL server on host db01 listens only on 127.0.0.1 port 5432. From your workstation you want to reach it by connecting to port 15432 on your own machine, tunnelled over SSH. Which command sets that up? machine-checked
- Which two statements about ssh-agent and ssh-add are correct? (Choose two.) machine-checked
- You want to send report.txt to your colleague Alice so that only she can read it, using GnuPG public key cryptography. Which key do you need, and which command uses it? machine-checked
- Immediately after creating a GnuPG key pair you want to produce the revocation certificate for the key whose ID is A1B2C3D4, so that you can withdraw the key later even if you lose the passphrase. Type the gpg command, with no output-file option. machine-checked
- The server web01 was rebuilt from scratch and keeps its old address. Your next ssh web01 aborts with a warning that the remote host identification has changed and refuses to continue. Which command removes just the stale entry from your ~/.ssh/known_hosts? machine-checked
- Which TWO statements about OpenSSH server host keys are correct? (Choose two.) machine-checked
- You are asked to create a new Ed25519 SSH identity for your own account, in the default file names, specifying nothing but the key type. Type the complete command. machine-checked
- A web application on your laptop listens on 127.0.0.1:3000. Your laptop can reach the shared host halof, but a colleague can only reach halof and not your laptop. halof's sshd is configured with GatewayPorts yes. You want the colleague to open the application as halof:8585. Which command, run from your laptop, sets that up? machine-checked
- You log into a remote server over SSH and start the graphical tool xterm, which fails because the DISPLAY variable is not set. Which client option lets the remote program draw on your local X server? machine-checked
- You connect from your workstation to bastion, and from there onward to db01, which trusts the same public key. The private key must not be copied onto bastion. Which option on the first connection makes the onward login work? machine-checked
- You want typing ssh web01 on its own to connect to 198.51.100.20 on port 2222 as the user deploy, and you want the shortcut to apply to your account only. Which file takes those settings? machine-checked
- You still have ~/.ssh/id_rsa but the matching id_rsa.pub was deleted by accident, and you need the public key text to add to a new server's authorized_keys. Which command reconstructs it? machine-checked
- Which THREE of the following GnuPG operations require your own private key to be present in ~/.gnupg? (Choose three.) machine-checked
- You want to check which correspondents' keys you already hold before encrypting anything. Type the gpg command, using its long option and no key arguments, that lists the public keys in your keyring. machine-checked
- A colleague asks for your GnuPG public key as text she can paste into an email. Which command produces exactly that on standard output? machine-checked
- You publish release.tar.gz and want users to be able to check its authenticity from a second, separate file, with the tarball itself left byte for byte unchanged. Which command produces that signature? machine-checked
- Signing several files one after another, you are asked for your GnuPG passphrase only the first time. Which component caches it, and takes default-cache-ttl in ~/.gnupg/gpg-agent.conf? machine-checked
Practise Securing data with encryption
The rest of objective 110
- Security administration tasks
- Host security
- Securing data with encryption — you are here