3

I'm trying to change the UID of user ec2-user to 500, when I try the following command getting the error UID already exists.

sudo usermod -u 500 ec2-user
usermod: UID '500' already exists

I'm doing a grep of /etc/passwd and can't find UID 500, so not sure how I can accomplish this.

Diego
  • 131
  • 1
  • 5

1 Answers1

2

According to the source code, usermod uses getpwuid for checking whether an uid already exists if the prefix flag is not used.

As stated in the documentation of getpwuid, it can also lookup the users from LDPA etc.:

The getpwnam() function returns a pointer to a structure containing the broken- out fields of the record in the password database (e.g., the local password file /etc/passwd, NIS, and LDAP) that matches the username name.

The getpwuid() function returns a pointer to a structure containing the broken- out fields of the record in the password database that matches the user ID uid.

You can run getent passwd 500 for checking whether the uid already exists. According to the documentation getent passwd passes each numeric key to getpwuid and displays the result. You can also see /etc/nsswitch.conf for checking your current configuration.

Antonio
  • 121
  • 6