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 caton the file, as shown below on the Terminal.

What is UID in Linux? How to find and change the UID Picture 1 View the contents of the file / etc / passwd

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.

  1. Column 1 - Name
  2. Column 2 - Password - If the user has set a password on this field, then it is indicated by the letter (x).
  3. Column 3 - UID (User ID)
  4. Column 4 - GID (Group ID)
  5. Column 5 - Gecos - Contains general information about the user and can be left blank.
  6. Column 6 - Home directory
  7. 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.

What is UID in Linux? How to find and change the UID Picture 2 The root has complete control over every aspect of the system

One 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 useraddassigned 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.

What is UID in Linux? How to find and change the UID Picture 3 There are 2 users Fosslinux_admin and Tuts

The 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 idon other groups. By executing the command alone idin the Terminal, it will display the UID of the currently logged in user.

What is UID in Linux? How to find and change the UID Picture 4 You can also run the id command on other groups

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 idon user example_user , you can see that this new user has UID 1003.

What is UID in Linux? How to find and change the UID Picture 5 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 userdelto 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.

What is UID in Linux? How to find and change the UID Picture 6 Existing user UID = 1001

Now, 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 useraddand assign the user a specific UID. See the syntax below.

sudo useradd -u 1111 user_2
What is UID in Linux? How to find and change the UID Picture 7 Create new users with specific UIDs

By running the command idon user_2 , we see that the user UID = 1111.

4.3 ★ | 15 Vote

May be interested

  • How to Change Time Zone on LinuxHow to Change Time Zone on Linux
    today's tipsmake will show you how to change the time zone on your linux computer. you can change the time zone on any linux distribution using the command line or command line menu depending on the linux version. if you are using mint, ubuntu or another distribution with a simple user interface and settings menu, you can also change the time zone right here.
  • How to change the keyboard layout in LinuxHow to change the keyboard layout in Linux
    all linux desktop environments make it easy for users to customize the keyboard layout according to language, region and personal preferences.
  • How to find ulimit for users on LinuxHow to find ulimit for users on Linux
    how can you find the ulimit value for a user account or a process on a linux system?
  • How to find out if the package is installed in LinuxHow to find out if the package is installed in Linux
    linux packages are just a collection of software and the way they are installed varies depending on the distribution. there are several ways to quickly check if a package is currently installed.
  • How to Change the Timezone in LinuxHow to Change the Timezone in Linux
    this wikihow teaches you how to change the time zone on a linux computer. you can change the timezone on every linux distribution by using the command line, or you can use the selection menu in the command line for different linux...
  • Why don't developers make more apps for Linux?Why don't developers make more apps for Linux?
    linux has a lot of software, but when you first switch, you may be disappointed that the operating system lacks familiar names. if you've been using linux for a while, you may also be disillusioned by certain types of software that have a relatively slow rate of change or lack of long-term support.
  • How to find broken symlinks in LinuxHow to find broken symlinks in Linux
    symbolic link or symlink is a way to simplify linux system management. here, tipsmake will guide you how to find and fix broken symlinks in linux.
  • 5 ways to make Linux desktops look great5 ways to make Linux desktops look great
    various tools, tips and tweaks can be used to personalize linux desktops. use the following 5 methods to personalize your linux desktop environment.
  • How to change DNS for Ubuntu, LinuxHow to change DNS for Ubuntu, Linux
    suppose for some reason you need to change dns for ubuntu, such as to speed up the page loading process or access a website blocked by isp, ..., but don't know how to do it. refer to tipsmake's article below to learn more details.
  • 3 main types of Linux distributions that you should know3 main types of Linux distributions that you should know
    linux is a powerful open source kernel that powers servers and desktop operating systems. one cool feature of linux is that you can modify and change it to your liking, which has led to thousands of linux distributions coming out over the years.