Other Articles

Servers – Ensure Users Own Their Home Directories

Support > Fixing Checks > Server

06 March, 2026

This check ensures that each user is the owner of their respective home directory.

User home directories are used to store personal files and environment configurations. If a home directory is not owned by the correct user, it may allow unauthorized access or prevent the user from properly managing their own files.

Check Details

  • Resource: Server
  • Check: Verify Ownership of Home Dirs
  • Risk: If home directories are not owned by their respective users, it may lead to improper access control and compromise accountability for files stored in the directory.

Remediation Steps

  1. Open a terminal session on the server with root or sudo privileges.
  2. Run the following script to identify home directories that are not owned by the respective user.

    grep -E -v '^(halt|sync|shutdown)' /etc/passwd | \
    awk -F: '($7 != "'"$(which nologin)"'" && $7 != "/bin/false") { print $1 " " $6 }' | \
    while read -r user dir; do
        if [ ! -d "$dir" ]; then
    echo "The home directory ($dir) of user $user does not exist."
        else
            owner=$(stat -L -c "%U" "$dir")
    
            if [ "$owner" != "$user" ]; then
                echo "The home directory ($dir) of user $user is owned by $owner."
            fi
        fi
    
    done
    
  3. For any home directory that is not owned by the correct user, change the ownership to the appropriate user.

    sudo chown <username>:<groupname> /home/<username>
    
  4. If necessary, recursively change the ownership of all files and directories within the user's home directory.

    sudo chown -R <username>:<groupname> /home/<username>
    

Note: On some distributions, /sbin/nologin may be replaced with /usr/sbin/nologin.