6.2.5 Ensure users own their home directories

Information

The user home directory is space defined for the particular user to set local environment variables and to store personal files.

Rationale:

Since the user is accountable for files stored in the user home directory, the user must be the owner of the directory.

Solution

Change the ownership of any home directories that are not owned by the defined user to the correct user.
The following script will create missing home directories, set the owner, and set the permissions for interactive users' home directories:

#!/bin/bash

awk -F: '($1!~/(halt|sync|shutdown)/ && $7!~/^(/usr)?/sbin/nologin(/)?$/ && $7!~/(/usr)?/bin/false(/)?$/) { print $1 ' ' $6 }' | while read -r user dir; do
if [ ! -d '$dir' ]; then
echo 'User: '$user' home directory: '$dir' does not exist, creating home directory'
mkdir '$dir'
chmod g-w,o-rwx '$dir'
chown '$user' '$dir'
else
owner=$(stat -L -c '%U' '$dir')
if [ '$owner' != '$user' ]; then
chmod g-w,o-rwx '$dir'
chown '$user' '$dir'
fi
fi
done

See Also

https://workbench.cisecurity.org/files/3219

Item Details

Category: ACCESS CONTROL

References: 800-53|AC-3, CSCv7|14.6

Plugin: Unix

Control ID: 453332f088a79db9b0ca892067cf62bc3e1cde2bf78931e8789959f729507d84