Comprehensive Guide to Linux Account Security
๐ก๏ธ Linux Account Security
Security on Linux systems starts at the account level. This guide explores key practices and tools for hardening Linux accounts based on advanced system administration and enterprise grade principles.
๐ Introduction
Managing user access is essential in preventing internal and external attacks on Linux systems. This post covers all the crucial components of Linux account security including Pluggable Authentication Modules (PAM), shadow passwords, account control, and sudo configuration.
๐ง Pluggable Authentication Modules (PAM)
PAM is a suite of shared libraries enabling the local system administrator to choose how applications authenticate users.
๐ Key Configuration Files
/etc/pam.d//etc/pam.d/login/etc/pam.d/sshd
๐ Module Interfaces
auth: Authenticates the user.account: Verifies if access is permitted.password: Updates passwords.session: Sets up and tears down login sessions.
โ๏ธ Control Flags
required,requisite,sufficient,optional- Example PAM configuration block
1auth required pam_securetty.so
2auth required pam_unix.so nullok
3account required pam_unix.so
4password required pam_pwquality.so retry=3
5session required pam_unix.so๐ฅ Linux Account Types
- Root: Superuser with UID 0. Unlimited access.
- System Accounts: UIDs < 1000. Created with
useradd -r. - User Accounts: UIDs โฅ 1000. Assigned to human users.
๐ Password and Shadow Files
๐ /etc/passwd vs /etc/shadow
/etc/passwd: Holds user information, readable by all./etc/shadow: Stores hashed passwords, accessible by root only.
๐ Conversion Utilities
1pwconv # Enable shadow passwords
2pwunconv # Revert to /etc/passwd only๐ Password Security
- Enforce strong passwords via
pam_pwquality. - Configure
/etc/security/pwquality.conf. - Enforce password history
1password required pam_pwhistory.so remember=5๐ Account Expiry Management
Manage password aging and expiry with chage
1chage -l username
2chage -M 90 -E 2025-12-31 usernameSettings in /etc/login.defs
1PASS_MAX_DAYS 90
2PASS_MIN_DAYS 1
3PASS_MIN_LEN 8
4PASS_WARN_AGE 7๐ Locking and Disabling Accounts
๐ซ Lock Account
1passwd -l username๐ Unlock Account
1passwd -u username๐ท Disable Login via Shell
1chsh -s /sbin/nologin username๐ Monitoring Authentication
๐ Useful Logs
/var/log/auth.log/var/log/secure/var/log/syslog
๐ฎ Intrusion Prevention
Use fail2ban
1sudo apt install fail2ban๐ Multifactor Authentication
Supported PAM Modules:
- Google Authenticator
- Duo Security (
pam_duo) - RSA SecurID
๐งโ๐ป Securing Root Access
Best Practices
- Avoid direct root logins.
- Use
sudoinstead ofsu. - Restrict root login via SSH
1PermitRootLogin noCheck for UID 0 accounts:
1awk -F: '($3 == "0") {print}' /etc/passwd๐ฎ Using and Configuring sudo
Benefits
- Granular control
- Audit trails
- No shared passwords
Configuration
- Use
visudofor editing/etc/sudoers. - Additional configs in
/etc/sudoers.d/.
Example Entries
1jason webdev01=(root) /sbin/apachectl
2%web web*=(root) /sbin/apachectl
3%wheel ALL=(ALL) ALLAliases
1User_Alias WEBTEAM = jason, bob
2Runas_Alias WEBUSERS = apache, httpd
3Host_Alias WEBHOSTS = web*, prodweb01
4Cmnd_Alias WEBCMNDS = /sbin/apachectl
5
6WEBTEAM WEBHOSTS=(WEBUSERS) WEBCMNDS๐งน Deleting User Accounts
1userdel -r username
2find / -user UID
3find / -nouserโ Summary
- PAM offers modular control over authentication.
- Shadow passwords secure password hashes.
- Lock, disable, and expire user accounts effectively.
- Use
sudowith fine grained permissions. - Implement multifactor authentication and intrusion prevention.
Linux account security is a foundational aspect of system administration and should not be overlooked. Proper configuration of accounts, permissions, and authentication methods is essential for maintaining a secure Linux environment.