Part 6 of 7 · 3 min read
The login path
The login path, PAM and keys
Think of a post office with a counter clerk who does not decide the rules, but follows a procedure card that says: check the ID, check the stamp, then check the signature. The procedure can be changed without changing the clerk. The analogy stops in one place: a procedure card is paper, and the PAM configuration is a set of files read by programs.
In plain words: PAM (pluggable authentication modules) is a library that programs such as login, sudo and sshd call to check a user. The checks are in modules, listed in files under /etc/pam.d, so the policy can change without changing the programs: add a second factor, change the hash method, or lock an account after failures. The test machine's directory has files such as common-auth and common-password, which hold the shared steps. sudo lets a permitted user run one command as root after checking the user's own password, and logs it. SSH keys avoid sending a secret. The user keeps a private key and the server holds the public key. The server sends a challenge, and only the holder of the private key can sign it correctly. The private key never leaves the user's machine.
A worked example. A user logs in over SSH with a key. The server looks up the user's public key in ~/.ssh/authorized_keys, sends a random challenge, receives a signature, and checks it with the public key. If it matches, sshd sets the user's IDs (page 2), changes to the home directory, and starts the shell. No password crossed the network, so there is nothing to guess and nothing to replay.
The key lines. The private key file should be readable only by its owner (mode 0600), and protected with a passphrase. If a server holds only public keys, a leak of the server's files does not give an attacker the ability to log in elsewhere.
PAM
PAM (pluggable authentication modules) is a library and a set of configuration files that let programs delegate user checks to modules. The modules and their order are chosen by an administrator, so the authentication policy can change without changing the programs that use it.
Example: sshd calls PAM, which runs the modules of /etc/pam.d/sshd to check the password and to open a session.
Interview angle
A common question is "How should a system store passwords?" A good answer says: never in plain text; a slow, salted hash with a per-user salt (yescrypt, bcrypt or Argon2); a shadow file readable only by root; and rate limits and a second factor on top.
Check yourself: 1. What does PAM let an administrator change without changing the programs? 2. Why does an SSH key login not send a secret over the network? 3. What mode should a private key file have?
Words you will meet
| Word | Meaning |
|---|---|
| Hash | A one-way function of a password. |
| Salt | A random value mixed into a hash and stored with it. |
| Cost | The work that one hash takes. |
| Brute force | Trying every possible secret. |
| PAM | Library that lets programs use pluggable login checks. |
Quick notes
- Authentication checks identity by something known, held or inherent. Authorization checks rights.
- Store a salted, slow hash, never the password. The shadow file is root-only.
- A salt makes equal passwords differ and defeats shared tables.
- Search time = password space / guesses per second. Each extra character multiplies the space by the alphabet size.
- On the test machine, yescrypt took about 14 ms and SHA-512 crypt about 1.6 ms for one hash.
- PAM makes login checks pluggable. SSH keys avoid sending a secret.