What is UID in Linux? How to Find and Change it?

What is UID in Linux How to Find and Change it

Using Linux, you come across the word User ID (UID), which represents a unique user. If you don’t know what UID is how to find and change the UID for a specific user, so, you are at the right place. This article will provide all information about UID and methods to find and change it.

What is UID in Linux?

A UID (short for; User Identifier) is a unique number allocated by Linux to every user in the system. The UID identifies the user to use system resources for that user only that’s why every user in the system has a unique UID. If multiple users have the same UID, they can access each other system resources, which is a security risk.

In most Linux distros, UID 0 is assigned to the root user, while the system users are assigned UID numbers from 1-500. The UID and other user details are present in the /etc/passwd system file. 

Let’s discuss how to find and change the UID.

How to Find UID in Linux?

User ID (UID) is the identification number of the user, which can be found using several commands. This section will use the “id” and “cat” commands to find the UID.

To find the UID, we can use the “u” option of the id command. To find the user id for “ubuntu”, run the below command: 

$ id -u ubuntu

Find UID of a user

The output shows the user ID of “ubuntu” is “1000”.

The cat command is used on the “/etc/passwd” file to get the user information. The information is filtered with the “grep” command for a specific user, “ubuntu”, as shown below:

$ sudo cat /etc/passwd | grep ubuntu

find UID

The output shows all the details of the “ubuntu” user with UID “1000”. 

Similarly, we have another user in the system named “john” to get his UID; the below command is used:

$ sudo cat /etc/passwd | grep john

Find UID using etc passwd file

The user “john” UID is “1001”.

How to Change UID in Linux?

The “usermod” command changes the “UID” for a specific user. The general syntax of the chmod command to change the UID is as follows:

$ usermod -u <new-UID> <user-name>
  • u: Allow to change the UID.
  • <new-UID>: Replace it with a new UID.
  • <user-name>: Replace it with the user name whose UID you want to change.

For instance, to change the UID of the user “john” having UID (1001) to the new UID (4000), the below-stated command is utilized:

Note: The sudo permissions are required to change the user ID.

$ sudo usermod -u 4000 john

Change UID of a user

Let’s verify that the “john” UID is changed to a new UID with the below command:

$ id -u john

Check UID for a specific user

The output shows that the “john” UID is changed to 4000 (from 1001).

How to Find UID and Change it?

The UID for a user can be found and changed directly using a single command, whose syntax is as follows:

$ sudo find / -user <old-uid> -exec chown -h <new-uid> {} \;
  • find: It allows you to find a specific UID.
  • user: Enables the user to use the UID.
  • <old-uid>: Replace it with the previous UID for the user, which needs to be changed.
  • exec: The option is used to execute the “chown” command on all files.
  • chown: Use to change the UID.
  • h: This option is used to change the UID of the symbolic link as well.

For example, to find and change the UID of the user “john” with a User ID (4000), use the following command:

$ sudo find / -user 1001 -exec chown -h 4000 {} \;

Change files to new owner using UID

That end of this guide.


The UID is a unique identification number assigned to every user by Linux to manage its system resources. It can be found using the “id” command or the “/etc/passwd” system file. The UID for the user can be changed using the “usermod” command, as discussed in the article.

Leave a Reply

Your email address will not be published. Required fields are marked *