OGOPSEC // Dispatch
Linux Login Protection: Beyond the Password
When people think about Linux login protection, they almost always think about the password prompt on the display manager. That prompt matters, but it guards only one door at one moment. A determined attacker has other ways in: a second virtual terminal, a machine left unlocked while you fetch coffee, a recovery shell at boot. Protecting the login means thinking about all of those, not just the first screen you see.
This post walks through the login surface on a Linux machine and shows how to tighten each part, with an honest note on what each measure actually buys you.
Start with a second factor, not a longer password
Past a certain point, a longer password stops helping against the attack that matters — because the common threat is not someone guessing it, but someone who already has it from a reused credential or a shoulder-surf. A second factor fixes that asymmetry. On Linux, the cleanest approach is a FIDO2/U2F hardware key through pam-u2f.
Then add the module to the PAM stack you want to protect (for example /etc/pam.d/sudo or your display manager's file):
Now a password alone will not open the gate — the physical key must be present and touched. The honest limit: this protects the login event. It does nothing once you are already inside an active session.
Close the virtual terminal gap
Your graphical login is not the only console. Linux offers several text terminals reachable with Ctrl+Alt+F2 through F6. If your login protection lives only in the desktop environment, those terminals can be a side door. Make sure any PAM hardening you apply covers login (the console) and not just the graphical greeter, and consider disabling unused TTYs on machines where you never need them.
On systemd systems you can limit the number of auto-spawned terminals in /etc/systemd/logind.conf with NAutoVTs, then reload logind. The point is simple: every place a credential is accepted needs the same policy, or the weakest one defines your security.
The unlocked machine is the real risk
Most "breaches" of a personal device are mundane: someone sits down at an unlocked screen. Two settings close most of that gap.
Auto-lock on idle
Set a short idle timeout in your desktop's privacy settings, or via gsettings on GNOME:
Lock when your key leaves
If you carry a hardware key, the strongest ergonomic rule is "pull the key, lock the screen." That turns walking away into a physical act you cannot forget. It can be wired up with a udev rule that triggers loginctl lock-sessions when the device is removed. The benefit is behavioral as much as technical: security that depends on remembering to lock will eventually fail; security tied to an object you are already carrying will not.
Do not forget the boot menu
All of the above is moot if an attacker can drop to a root shell from the bootloader. GRUB can be told to boot normally but require a password before anyone edits a boot entry or enters a recovery mode. On RHEL-family systems:
On Debian/Ubuntu you generate a PBKDF2 hash with grub-mkpasswd-pbkdf2 and add it to the GRUB configuration. Honest limit: a bootloader password stops casual edit-the-kernel-line attacks; it does not stop someone who removes the drive entirely. That is what disk encryption is for, and the two belong together.
A login-protection checklist
- A hardware second factor via
pam-u2f, applied to every gate (greeter, consolelogin,sudo). - Account lockout with
pam_faillockto blunt guessing. - Idle auto-lock set to a few minutes, lock-on-key-removal if you carry a key.
- A GRUB password so recovery mode is not a free shell.
- Full-disk encryption underneath it all, so pulling the drive gains nothing.
Fail closed, not open
There is one design principle worth stating outright: a login system should fail closed. If the second factor is missing, the correct behavior is to deny the session, not to quietly fall back to a password. A system that degrades to "just the password" the moment the key is absent has given an attacker the roadmap. This is the behavior Dire Wolf enforces — no key present, no session, full stop — alongside the FIDO2 and lock-on-removal pieces described above. Whether you assemble these controls yourself or use a packaged setup, aim for that same property: when something is wrong, the door stays shut.
Password strength is the smallest part of login protection. The larger part is making sure every door uses the same lock, and that walking away locks the screen without you having to think about it.