Sub topic 14
User Accounts, Shells, Session Environment, and System Logging
Assume you can use sudo, edit configuration files, and inspect systemd units. Test changes on a non-production server first. CIS recommendations vary by distribution, so confirm the benchmark for your Linux version before enforcing a value.
User accounts, shells, and session environment
A server should have only the accounts and login paths that its workload needs. Review local accounts, especially accounts with a valid login shell:
# Show accounts with UID 0
getent passwd | awk -F: '$3 == 0 {print $1 ":" $6 ":" $7}'
# Show accounts that have an interactive shell
getent passwd | awk -F: '$7 !~ /(nologin|false)$/ {print $1 ":" $7}'
# Review password aging for one account
sudo chage -l deployA service account normally uses /usr/sbin/nologin or /bin/false. Do not disable an account until you know which service or scheduled task uses it. Remove stale accounts through your approved access process, and preserve evidence of who approved the change.
For interactive users, set account aging and a controlled shell environment. A umask is a permission mask that removes permissions from newly created files. 027 usually prevents access by users outside the file owner and group.
# Apply an example policy to an existing account
sudo chage --mindays 1 --maxdays 90 --warndays 14 deploy
sudo usermod --shell /bin/bash deploy
# /etc/profile.d/60-security.sh
umask 027
TMOUT=900
readonly TMOUT
export TMOUTTMOUT logs out an idle interactive shell after 900 seconds. Check that this does not disrupt administrative scripts or long-running maintenance sessions. Keep system accounts out of interactive login lists rather than changing their shells blindly.
| Check | Why it matters | Example evidence |
|---|---|---|
| UID 0 accounts | Every UID 0 account has full local privilege | `getent passwd` |
| Login shells | Unneeded interactive access increases risk | `/etc/passwd` shell field |
| File creation mask | Limits permissions on new files | `umask` |
| Password aging | Reduces exposure from forgotten credentials | `chage -l user` |
Configuring journald and rsyslog
journald is the systemd log service. It collects service, kernel, and boot messages. rsyslog is a separate logging service that can write traditional text files or forward events to a central collector. Use both when local retention and compatibility with existing log tools are required.
Create persistent journal storage and a bounded retention policy:
# /etc/systemd/journald.conf.d/60-retention.conf
[Journal]
Storage=persistent
SystemMaxUse=1G
MaxRetentionSec=30day
ForwardToSyslog=yesApply and verify the settings:
sudo systemctl restart systemd-journald
journalctl --disk-usage
journalctl -u sshd --since "1 hour ago"If your distribution uses rsyslog, configure security messages according to its standard path:
# /etc/rsyslog.d/60-security.conf
authpriv.* /var/log/secureDebian-family systems commonly use /var/log/auth.log instead. Test the complete path rather than assuming that a file exists:
sudo systemctl enable --now rsyslog
logger -p authpriv.notice "CIS logging test"
sudo journalctl --since "1 minute ago" | tail
sudo tail -n 20 /var/log/secureRestrict log files, configure rotation, and forward important events to a separate system when possible. Local logs cannot prove what happened after an attacker gains control of the host.
Exercise
A service account appears in the list of users with interactive shells. What should you verify before changing its shell, and which logs should you inspect afterward?
Show answer
Identify the service, scheduled jobs, and deployment tools that use the account. After the change, inspect the service status, journald entries, and rsyslog output for failed starts or authentication errors.