Skip to Content

3 ways to check user id in Linux

In Linux, there are a few ways to check your user id. One way is to use the id command. This command prints out information about the current user, including the user id. Finally, you can use the cat /etc/passwd command to view a list of all users on your system and their corresponding user ids.

understanding users in Linux

Linux has two types of users: human users and system users. Each user has a unique identity (UID), and at least one group identification (GID). All users have one primary group and may be members of multiple groups.

Each human user owns a home directory for their personal files. User home directories belong in /home and are named for the owner. System users represent system services and processes. System users need user accounts for controlling their privileges and do not have logins or directories in /home.

understanding user ids in Linux

In Linux, user ids for human users are assigned automatically when the user account is created. The range of user ids is usually 1000-65535, but can vary depending on the system.

User id 0 is reserved for the root user, and user ids in the range of 0-999 are typically reserved for system users. User ids less than 1000 are considered privileged users and can perform actions that could potentially damage the system. For this reason, it is best to avoid using these user ids unless absolutely necessary.

check user id in Linux with id command

The easiest way to check a user id in Linux is using id command. simply type “id” into the terminal and press enter. It will print out information about the current user, including the user id.

$ id
uid=50291(ocp) gid=50291(ocp) groups=50291(ocp)

check user id of a specific user in Linux

To check the UID of a specific user in Linux, you can use the id username command. This command will print out information about the specified user, including their UID. Only the root user has permission to run this command.

$ id ocp
uid=50291(ocp) gid=50291(ocp) groups=50291(ocp)

check user id in Linux with cat /etc/password command

Another way to check user id in Linux is using cat /etc/passwd command. This command will print out a list of all users on the system and their corresponding user ids.

$ cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:2987:2987:bin:/bin:/sbin/nologin
daemon:x:2988:2988:Daemon User:/usr/sbin:/sbin/nologin

The output of this command can be quite long, so you may want to use the grep command to filter the results. For example, the following command will only print out lines that contain the word “ocp”.

$ cat /etc/passwd | grep ocp
ocp:x:50291:50291::/home/ocp:/bin/bash

What is the root user in Linux?

The root user is the superuser in Linux. The root user has full access to all files and folders on the system and can perform any action. It is important to be careful when using the root user, as it is easy to accidentally delete or modify critical system files.

How to change the user id of a user in Linux?

The UID of a user can be changed using the usermod command. This command can only be run by the root user. To change the UID of a user, use the following syntax: usermod -u new_uid username

For example, to change the UID of the user ocp to 1000, you would use the following command:
usermod -u 1000 ocp

Conclusion

In this article, we showed you two ways to check user id in Linux. We also explained what the root user is and how to change a user’s UID. Thanks for reading! I hope this was helpful. If you have any questions, please feel free to leave a comment below.