How To Find UID And GID Using Id Command In Linux/Unix?
This post was last updated on August 1st, 2020 at 12:45 pm
Linux/Unix are multi-user operating systems that means different users can access and use system resources simultaneously. To access the resources of a system you must have a user account on that system. And a group is a collection of users.
A system identifies users and groups with a UID and GID respectively. In this article, we will discuss to find the UID and GID from Linux.
UID (User Identifier)
UID is a number assigned to each user in a Linux or Unix system. The system identifies a user with its UID and uses it to determine which system resources a user can access. For example – the root user has UID 0.
GID (Group Identifier)
A group is a collection of users having similar permissions. Like a user who is identified by the UID, a group is identified by the GID in a system. GID 0 is reserved for the root group.
The id Command
Unix like operating system provides id command to display the UID and GID of a user. If the command is executed without any argument, it will print the user information of the current user. Following is the syntax of id command –
id [option] username
You can use the following options with this command –
|It will print only effective group IDs|
|Display all group IDs|
|Prints a name instead of a number for, -ugG|
|Print only effective user IDs|
|Display the real ID instead of the effective ID, with -ugG|
|Delimit entries with NUL characters, not whitespaces|
|Ignore the compatibility with other versions|
|Print only the security context of the process|
|Output the version information and exit|
For more details, you can see the manual page of id command by using –
How to display the UID and GID of the current user?
To display the user ID and Group ID of the current user, use the id command without any arguments –
Now here you can see the UID and GID of user lalit both are 1000
How to display the UID and GID of a specific user?
To display the user ID of a specific user use the option
-u with the id command, Run the following command –
id -u username
For example –
id -u lalit
This will display the user ID of lalit.
And to display the group ID use
-g option with id command –
id -g lalit
This will display the group ID of lalit.
How to list all the groups a user belongs to?
Use the option
-G with id command to display the list of the groups a user belongs to –
id -G lalit
Or use the option
-n to display name instead of GID –
id -nG lalit
Is there any other way to display the UID and GID of a user?
The information such as UID, GID, default shell, etc is stored in
/etc/passwd file. You can display the content of this file by using the following command in your terminal –
cat /etc/passwd | less
Now you will see a list of users with some other information. There are seven places separated by a colon, third and fourth places are UID and GID respectively. For example – UID and GID of the root user are 0 and 0.
That’s all for now. If you have any queries or suggestions related to this topic then you can write to us in the comments.
You might also like
A hard disk can have various partitions on it. Partition refers to the logical divisions of a physical disk that makes it easy to organize and share the data. You
This post was last updated on August 1st, 2020 at 04:51 pmWhile working with files especially with text files in Linux operating system sometimes you may need to count the
This post was last updated on August 1st, 2020 at 10:31 amKDE is among one of the most popular free and opensource desktop environments. It provides various built-in tools. KDE