Other Articles

Servers – Ensure No Duplicate User Names Exist

Support > Fixing Checks > Server

06 March, 2026

This check ensures that no duplicate usernames exist in /etc/passwd.

Duplicate usernames may occur if the /etc/passwd file is manually modified. This can lead to authentication conflicts and unintended access to files associated with another user.

Check Details

  • Resource: Server
  • Check: Ensure no duplicate user names exist
  • Risk: Duplicate usernames can result in authentication ambiguity and unauthorized access to files associated with the original user.

Remediation Steps

  1. Open a terminal session on the server with root or sudo privileges.
  2. Run the following script to identify duplicate usernames in /etc/passwd.

    #!/bin/bash
    
    cut -f1 -d":" /etc/passwd | sort | uniq -c | while read x ; do
      [ -z "$x" ] && break
      set - $x
      if [ $1 -gt 1 ]; then
        uids=$(awk -F: '($1 == n) { print $3 }' n=$2 /etc/passwd | xargs)
        echo "Duplicate User Name ($2): $uids"
      fi
    done
    
  3. Review the output to identify duplicate usernames and their associated UIDs.
  4. Decide which account should retain the original username and which needs modification.
  5. Rename the duplicate user using the usermod command.

    usermod -l <new_username> <old_username>
    
  6. Update the user's home directory name if required.

    usermod -d /home/<new_username> -m <new_username>
    
  7. Verify that no duplicate usernames exist by re-running the audit script.
  8. Implement regular system audits and avoid manual edits to /etc/passwd.