Other Articles

Servers – Ensure No Users Have .netrc Files

Support > Fixing Checks > Server

06 March, 2026

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

The .netrc file contains authentication information used to log into remote hosts for file transfers via FTP. Since this file stores credentials in plain text, it poses a significant security risk if present on the system.

Check Details

  • Resource: Server
  • Check: Ensure No Users Have .netrc Files
  • Risk: The presence of .netrc files may expose user credentials because the file stores authentication information in unencrypted form.

Remediation Steps

  1. Open a terminal session on the server with root or sudo privileges.
  2. Run the following script to identify .netrc 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
            if [ ! -h "$dir/.netrc" -a -f "$dir/.netrc" ]; then
    echo ".netrc file $dir/.netrc exists"
    fi
    fi
    done
    
  3. Establish a monitoring policy to report user .netrc 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.