5.3.2 Ensure system accounts are secured

Information

There are a number of accounts provided with most distributions that are used to manage applications and are not intended to provide an interactive shell.

It is important to make sure that accounts that are not being used by regular users are prevented from being used to provide an interactive shell. By default, most distributions set the password field for these accounts to an invalid string, but it is also recommended that the shell field in the password file be set to the nologin shell. This prevents the account from potentially being used to run any commands.

Solution

Run the commands appropriate for your distribution:

Set the shell for any accounts returned by the audit to nologin:

# usermod -s $(which nologin) <user>

Lock any non root accounts returned by the audit:

# usermod -L <user>

The following command will set all system accounts to a non login shell:

awk -F: '($1!="root" &amp;&amp; $1!="sync" &amp;&amp; $1!="shutdown" &amp;&amp; $1!="halt" &amp;&amp; $1!~/^+/ &amp;&amp; $3>='"$(awk '/^s*SYS_UID_MIN/{print $2}' /etc/login.defs)"' &amp;&amp; $3<='"$(awk '/^s*SYS_UID_MAX/{print $2}' /etc/login.defs)"' &amp;&amp; $7!="'"$(which nologin)"'" &amp;&amp; $7!="/bin/false") {print $1}' /etc/passwd | while read user; do usermod -s $(which nologin) $user; done

The following command will automatically lock not root system accounts:

awk -F: '($1!="root" &amp;&amp; $1!~/^+/ &amp;&amp; $3>='"$(awk '/^s*SYS_UID_MIN/{print $2}' /etc/login.defs)"' &amp;&amp; $3<='"$(awk '/^s*SYS_UID_MAX/{print $2}' /etc/login.defs)"') {print $1}' /etc/passwd | xargs -I '{}' passwd -S '{}' | awk '($2!="L" &amp;&amp; $2!="LK") {print $1}' | while read user; do usermod -L $user; done

See Also

https://workbench.cisecurity.org/benchmarks/12218

Item Details

Category: ACCESS CONTROL, IDENTIFICATION AND AUTHENTICATION

References: 800-53|AC-1, 800-53|AC-2, 800-53|IA-4, 800-53|IA-5

Plugin: Unix

Control ID: 707cb2348022988d29a39ac833207e27ac68c3732a67b4bbed5dbc901bafbbee