Linux Labs

Server security / Stage 4 of 10

PAM: password policy and lockout

Not running Starting usually ~20 s
Leave the lesson

Step 7 of 8 · lab · 30 minmedium

A password can be anything

Interns change their own passwords and the system accepts any of them, while guessing a password can go on forever. Introduce a password policy and a lockout after failed attempts without losing your own key login and sudo.

Situation

Interns are joining the server team. Their accounts are created with a temporary password, and after that everyone changes it themselves with passwd. The intern intern set the password qwerty12 — the system did not object. Guessing a password can go on forever too: wrong passwords in su have no consequences.

You are the administrator: you log in with a key (ssh localhost) and work through sudo. The intern's account is handy for checking the result: su - intern, password qwerty12.

Task

  1. With passwd, a user cannot set a password shorter than 12 characters or with fewer than three character classes (lowercase, uppercase, digits, others). A password that follows these rules is accepted.
  2. The rules are written in /etc/security/pwquality.conf (or in a file in /etc/security/pwquality.conf.d/) — pwscore sees them.
  3. After three wrong passwords in a row the account is locked for any password login: the console, su, sudo. A successful login before the lockout resets the counter.
  4. Your own access is intact: student's key login, sudo and the console login work as before.

A mistake in /etc/pam.d can close both logins and sudo. Edit PAM from a root shell sudo -i and do not leave it until su - student -c 'sudo -n true' finishes without an error. There is no internet on the machine; everything you need is already installed.

Lab · on your own

No commands are given in this lab: type them in the terminal yourself. Goals are checked on the machine after every command.

Goals

0 of 4
  • pwscore rejects passwords shorter than 12 characters or with fewer than three classes and accepts a compliant one — not done yet
  • passwd does not let a user set a weak password and accepts a compliant one — not done yet
  • Three wrong passwords in a row lock the account for any password login, and a successful login resets the counter — not done yet
  • student logs in with the key, and sudo and the console login work as before — not done yet
Ctrl+Enter
Starts the machine node1 · Ubuntu 24.04

The machine is starting

Hints

0 of 3

Lab goals

0 of 4
  • pwscore rejects passwords shorter than 12 characters or with fewer than three classes and accepts a compliant one — not done yet
  • passwd does not let a user set a weak password and accepts a compliant one — not done yet
  • Three wrong passwords in a row lock the account for any password login, and a successful login resets the counter — not done yet
  • student logs in with the key, and sudo and the console login work as before — not done yet
node1 Ubuntu 24.04

Lab goals

0 of 4
  • pwscore rejects passwords shorter than 12 characters or with fewer than three classes and accepts a compliant one — not done yet
  • passwd does not let a user set a weak password and accepts a compliant one — not done yet
  • Three wrong passwords in a row lock the account for any password login, and a successful login resets the counter — not done yet
  • student logs in with the key, and sudo and the console login work as before — not done yet
Loading…