Other Articles

Servers – Ensure No Users Have .rhosts Files

Support > Fixing Checks > Server

06 March, 2026

This check ensures that no users have .rhosts files in their home directories.

The .rhosts file is used to allow trusted remote logins without requiring a password. If present, it may allow unauthorized remote access to the system and expose information that could be used by attackers.

Check Details

  • Resource: Server
  • Check: Ensure No Users Have .rhosts Files
  • Risk: The presence of .rhosts files may allow passwordless remote access or expose trust relationships that attackers could exploit.

Remediation Steps

  1. Open a terminal session on the server with root or sudo privileges.
  2. Run the following script to identify .rhosts files in user home directories.

    grep -E -v '^(root|halt|sync|shutdown)' /etc/passwd | \
    awk -F: '($7 != "'"$(which nologin)"'" && $7 != "/bin/false") { print $1 " " $6 }' | \
    while read user dir; do
        if [ ! -d "$dir" ]; then
    echo "The home directory ($dir) of user $user does not exist."
        else
            for file in $dir/.rhosts; do
                if [ ! -h "$file" -a -f "$file" ]; then
    echo ".rhosts file in $dir"
    fi
    done
    fi
    done
    
  3. If any .rhosts files are detected, review them and remove them if they are not required for system operations.
  4. Establish a monitoring policy to report user .rhosts files and determine the appropriate action to be taken according to site policy.

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