Other Articles

Servers – Ensure All Users' Home Directories Exist

Support > Fixing Checks > Server

06 March, 2026

This check ensures that all users defined in /etc/passwd have valid home directories that exist on the system.

If a user account has a home directory configured but the directory does not actually exist, the user may be placed in the root directory (/) when logging in. This can prevent proper environment setup and may cause permission or configuration issues.

Check Details

  • Resource: Server
  • Check: Check Existence of Home Dirs
  • Risk: If users are configured without existing home directories, they may be placed in the root directory during login, which can lead to improper environment configuration and potential security concerns.

Remediation Steps

  1. Open a terminal session on the server with root or sudo privileges.
  2. Run the following script to identify users whose home directories do not exist.
  3. 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."
        fi
    done
    
  4. If any users are reported, create the missing home directory for the user.
  5. sudo mkdir -p /home/<username>
    
  6. Assign ownership of the home directory to the respective user.
  7. sudo chown <username>:<username> /home/<username>
    
  8. If a user does not have a home directory, remove the user account or assign a valid directory as appropriate.