What is UID in Linux? How to find and change the UID
If you've ever interacted with Linux systems, chances are you've come across these two words, UID and GID. If you are not familiar with them, let's dig deeper through the following article.
What is UID in Linux?
UID stands for User Identifier, while GID stands for Group Identifier. In this specific article, TipsMake.com will focus on User Identifier (UID).
The UID is a unique identifier assigned to every user on the Linux system. The main role of UID is to identify users with the Linux kernel.
It is used to manage resources that users have access to in the system. That is one of the reasons to use unique UID for every available user. On the other hand, if there are two users listed with the same UID, both may have access to resources for the other.
Where to find stored UID?
You can find the UID in the / etc / passwd file, which is also the file that stores all registered users in the system. To view the contents of the / etc / passwd file, run the command cat
on the file, as shown below on the Terminal.
The / etc / passwd file contains all the necessary attributes or basic information about every user on the system. Data is displayed in 7 columns, as listed below. These fields are separated by colons (:). This file also contains the system-defined accounts and groups needed to install, run, and update the appropriate system.
- Column 1 - Name
- Column 2 - Password - If the user has set a password on this field, then it is indicated by the letter (x).
- Column 3 - UID (User ID)
- Column 4 - GID (Group ID)
- Column 5 - Gecos - Contains general information about the user and can be left blank.
- Column 6 - Home directory
- Column 7 - Shell - The path to the default shell for the user.
Determine the UID
From the image above, the first user listed on the file is root. The root has complete control over every aspect of the system. The root user is assigned UID Zero (O) and GID (0). Followed by system-defined accounts and groups.
The root has complete control over every aspect of the systemOne more thing to note is that UID = 0 and GID = 0 are what give root users all the permissions in the system. If you want to prove it, change the root name to something else like example_User and create a new root user with the new UID and GID.
Also, system-defined accounts and groups by root user have UID 1,2,3,4, etc. That's because most Linux systems give the first 500 UIDs to system users. . Other users add with a command useradd
assigned with a UID of 500 or more. In Ubuntu and Fedora systems, a new user, or even a user created during the installation process, is granted a UID of 1,000 or more.
You can see this in the image below, where there are 2 users Fosslinux_admin and Tuts.
There are 2 users Fosslinux_admin and TutsThe tuts user was created during the installation and assignment of UID 1000. The remaining user, fosslinux, was added later and issued UID 1001.
How to find the user UID, group or account
The article discussed how to find a UID by displaying the contents of the / etc / passwd file. There is a quicker and easier way using commands id
.
For example, to find the UID of Fosslinux_admin and Tuts users, execute the command below. You may be asked to enter the root password.
id fosslinux_admin id tuts
You can also run commands id
on other groups. By executing the command alone id
in the Terminal, it will display the UID of the currently logged in user.
How to change the UID
Suppose you are managing a system with many users. If a user leaves the company, you'll probably need to assign the new user the UID of the employee who quit.
First, create a temporary user for this example. Posts will use the command useradd
. You will need to have root access.
useradd example_user
By running the command id
on user example_user , you can see that this new user has UID 1003.
Now, delete user Fosslinux_admin with UID = 1001 and assign it to new user. Posts will use the command userdel
to remove users.
sudo userdel -r fosslinux_admin
After doing that, the UID will be assigned a new user - example_user - UID belongs to Fosslinux_admin. That is UID = 1001. The article will do this by command usermod
.
usermod -u 1001 exmple_user
By running the id command on the user, for example, _user, we see that the user currently has UID = 1001.
Existing user UID = 1001Now, when you assign an old user's UID to a new user, you'll need to sync these files with all other files that belong 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 {} ;
Create new users with specific UIDs
Alternatively, you can create a new user with the command useradd
and assign the user a specific UID. See the syntax below.
sudo useradd -u 1111 user_2
Create new users with specific UIDs By running the command id
on user_2 , we see that the user UID = 1111.
You should read it
- 14 interesting Linux commands in Terminal
- How to find, set and change IP addresses on Linux
- How to change Google DNS on Linux
- Compare the most popular Linux distributions today
- 5 ways to make Linux desktops look great
- Why don't developers make more apps for Linux?
- 3 main types of Linux distributions that you should know
- 7 best Linux distributions based on Red Hat
- How to change desktop theme on Linux Mint
- Basic Linux commands everyone needs to know
- What's new in Linux Kernel 5.18?
- Linux Mint 20.2 'Uma' Released: What's Notable?
Maybe you are interested
US users can now access ChatGPT via 1-800-CHATGPT
How to Change the Default User Account Avatar in Windows
2 features users don't like in Photoshop Express photo editing application
Microsoft still recommends 15-year-old backup solution for Windows 11 and 10 users
Canonical Urges Ubuntu 20.04 LTS Users to Upgrade or Purchase Extended Support
Microsoft removes a barrier preventing users from updating to Windows 11 24H2