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

A UID is a unique identification number assigned to every user in a Linux system. The primary role of UID is to identify the user to the Linux kernel. Let's find out where they are stored, and how to change it for a user?

If you have interacted with Linux systems, there is a probability you have come across these two words, UID and GID. If you have no clear idea about them, then follow along with this article.

What is UID in Linux?

A UID is an abbreviation of the word User Identifier, while GID is an abbreviation of the word Group Identifier. In this particular article, we will focus on the User Identifier (UID).

A UID is a unique identification number assigned to every user present in a Linux system. The primary role of the UID number is to identify the user to the Linux kernel.

It is used to manage the system resources that a user has access to in the system. It is one of the reasons for using a unique UID for every user available. Otherwise, if we have two users listed under one UID, then they could both have access to resources meant for the other.

Where to find stored UID?

You can find the UID in the /etc/passwd file, which is the file that also stores all users registered in the system. To view the /etc/passwd file contents, run the cat command on the file, as shown below on the terminal.

List contents of the passwd file
List contents of the passwd file

The /etc/passwd file holds all necessary attributes or basic information about every single user in the system. The data is displayed in seven columns, as listed below. These fields are separated by colons (:). This file also contains system-defined accounts and groups required for proper installation, running, and update of the system.

Column 1 – Name
Column 2 – Password – If the user has set a password on this field, then it is indicated with the letter (x).
Column 3 – UID (User ID)
Column 4 – GID (Group ID)
Column 5 – Gecos – Contain general information about the user and can be empty.
Column 6 – Home directory
Column 7 – Shell – The path to the default shell for the user.

Identify the UID

From the image above, the first user listed on the file is root. Root has overall control over every aspect of the system. The root user is assigned UID Zero (O) and GID (0). The other that follow are the system-defined accounts and groups.

The root user
The root user

One more thing to note is that UID = 0 and GID = 0 are what give the root user all the powers in the system. If you wish to prove so, rename the root to something else like Example_User and create a new root user with a new UID and GID. You will realize that the Example_User will still have elevated privileges despite not having the username root.

As you will also notice from the image, the system-defined accounts and groups that follow the root user have the UID 1,2,3,4,… and so on. It is because most Linux systems reserve the first 500 UID for system users. Other users added with the useradd command are assigned UID from 500. In Ubuntu and Fedora systems, a new user, even one created during the installation process, is given the UID from 1000 and above.

You can see this in the image below, where we have two users. Fosslinux_admin and Tuts.

List UID of current users
Listing UID of current users

The user “tuts” was created during the installation process and is assigned the UID 1000. The other user, “fosslinux,” was added later and was given the UID 1001.

How to find the UID of a User, Group or an account

We have discussed how we can find a UID by displaying the contents of /etc/passwd file. There is a faster and easier way. We will use the id command.

For example, to find the UID of user Fosslinux_admin and Tuts, execute the command below. You might be required to enter the root password.

id fosslinux_admin
id tuts

Use ID command to find ID of users
Use ID command to find the ID of users

We can also run the id command on other groups, as shown below. By executing the id command alone in the terminal, it will display the UID of the current logged in user. See the image below.

List UID of other groups and accounts
List UID of other groups and accounts

How to change UID’s

Suppose you are managing a system with a lot of users, say an organization or institution. If a user left the company, you would probably need to assign the new user the UID of the employee who quit.

Let’s first create a temporary user for this example. We will use the useradd command. You will need to have root privileges. See the command below.

useradd example_user

By running the command id on user example_user, we can see that this new user has the UID 1003

Create user, example_user
Create user, example_user

Now, let’s delete the Fosslinux_admin user who had the UID = 1001 and assign it to our new user. We will use the userdel command to remove the user.

sudo userdel -r fosslinux_admin

Once done that, we will assign our new user – example_user, the UID that belonged to fosslinux_admin. That is UID = 1001. We will do this using the usermod command.

usermod -u 1001 exmple_user

By running the id command on the user, for example, _user, we see that the user now has the UID = 1001.

Change a UID to a new user
Change a UID to a new user.

Now once you have the new user the UID of the old user, you will need to sync these with all other files that belonged to the old user. You can do this by executing the command below.

find / -user [UID_of_old_user] -exec chown -h [new_user] {} \;
e.g
sudo find / -user 1001 -exec chown -h user_2 {} \;

Update the newuser with associated files of old user
Update the newuser with associated files of the old user

Create a New User With a Specific UID

Alternatively, we can create a new user with useradd command and assign the user a specific UID. See the syntax below.

sudo useradd -u 1111 user_2

By running the id command on user_2, we see that the user’s UID = 1111.

Create a User with a new UID
Create a User with a new UID

Conclusion

That’s it! Everything you need to know about UID’s in Linux systems. If you think we missed a meaningful concept or need any clarification, don’t hesitate to let us know in the comment section below.

Arun Kumar
Arun did his bachelor in computer engineering and loves enjoying his spare time writing for FOSS Linux. He uses Fedora as the daily driver and loves tinkering with interesting distros on VirtualBox. He works during the day and reads anything tech at night. Apart from blogging, he loves swimming and playing tennis.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

STAY CONNECTED

23,437FansLike
375FollowersFollow
16SubscribersSubscribe

LATEST ARTICLES

How to change Hostname on Ubuntu

Generally, a hostname is just an assigned name to a computer, laptop, or any other connected device to a network. You can say a hostname is a computer's nickname, and it is used to identify the machine over the network uniquely.

Manjaro vs. Ubuntu – which is better for you?

If you are a person associated with Computer technology and spend most of the time in the open-source arena, you must have heard or worked with some of the popular Linux distributions we have in the market. Some of the names that you will never miss are; Ubuntu, Arch Linux, Debian, and Mint.

9 Useful Tips Working with Operating System using Python

There are several situations when we want to work with the operating system using python. We may want to see the user details or want to do some tasks with the files and directories. If you are a system administrator, you will find it useful to work with Operating System as one can easily automate some repeating tasks of the Operating System using python.

System76 Lemur Pro Review

Buyers who wish to go for a machine that is based on Linux often show interest in Chromebooks due to the form factor and extended battery life capabilities. Although ChromeOS power these machines, users can still miss out on a more genuine Linux experience. For those who happen to agree, the new Lemur Pro by System76 might get some heads turning.

Top 10 New Features in Linux Kernel 5.8

Linus Torvalds recently announced the release of Linux Kernel 5.8, and he seems delighted with it. He has pointed it out as the most significant release of all time. To developers, this new kernel comes with an addition of 800,000 new code lines and more than 14,000 changed files. To the average user, you might not see many eye-candy changes, as seen in the earlier releases.

How to install Flutter on Linux

Do you want to install Flutter and start creating awesome Android and iOS applications? Then you have come to the right place. Here is a comprehensive tutorial on how to install Flutter on Linux. If you are new to Flutter, don't worry, we got that covered too as we shall go in-depth understanding of Flutter and what it brings to the table.

MUST READ

Buyers who wish to go for a machine that is based on Linux often show interest in Chromebooks due to the form factor and extended battery life capabilities. Although ChromeOS power these machines, users can still miss out on a more genuine Linux experience. For those who happen to agree, the new Lemur Pro by System76 might get some heads turning.
Linux is growing faster than ever. As per the latest report, there is a drop in the Windows 10 market share for the first time, and Linux's market share has improved to 2.87% this month. Most of the features in the list were rolled out in the Pop OS 20.04. Let's a detailed look into the new features, how to upgrade, and a ride through video.

Scrcpy – Control Android devices from a Linux desktop

Scrcpy is a desktop program that can be used to access your Android phone's system and interface through your computer. The app is quite convenient, and some of its best features are highlighted below.

10 Reasons to use Cinnamon as your Desktop Environment

With the release of Gnome 3 in 2011, there was quite a mixed reaction from users and developers. Most of them preferred the original Gnome that got forked, and one of those forks was Cinnamon. Since the release of Cinnamon 2.0, Cinnamon has evolved to become a desktop environment by itself.

Top 5 reasons to switch from Windows to Linux right now

Do you love Windows or Linux? Being on a Linux website, it's not hard to take a guess, but what are the strong reasons to switch to Linux? Linux is a 100% free OS. Is that reason alone enough? Let's find out! Never have there been more compelling reasons to make the switch. Here are just five great reasons for users to create that magical move from the wayward world of Windows to the lauded land of Linux.

5 Things to do when your Linux system GUI freezes

All operating systems freeze at some point and, Linux distributions are no exceptions. In this post, we are going to look at five methods you can apply to your frozen system before thinking of plugging out the power cable or holding down the power button to power off the PC.