Every user in Linux is assigned with unique IDs, a.k.a. UIDs, and groups are assigned with group IDs, a.k.a. GIDs; groups can even contain more than one user identity that you can later use to manage users in that group.
To know all the users’ UIDs and groups’ GIDs in your system for user management, you can use the built-in id command.
|Root or Sudo Privileges
|Ubuntu, Manjaro, Fedora, etc.
Syntax of the ID Command
The id command takes two arguments: one for option and another for username.
$ id [OPTION] [USERNAME]
Display the User’s UID, GID, and Groups to Which They Belong
The following command, without any arguments, will print the current user’s ID (UID), group ID (GID), and groups to which they belong.
To get information about different users, specify their username with the id command.
$ id jake
Display Current User Identity as a Number
-u” or “
--user” flag is used to display the current user’s identity as a number without a username.
$ id -u
Display Current Group Identity as a Number
-g” or “
--group” flag is used to display the current group identity as a number.
$ id -g
Display the Real UID and GID Instead of the Effective Ones
The real ID is the one owned by your system and points towards your user account; the effective ID is identical to the real ID with some limitations.
$ id -r -u #Get user real UID
$ id -r -g #Get group real GID
Display All Groups IDs to Which the User Belongs as a Number
-G” or “
--groups” flag will print all the group IDs as a number in your system to which the current user belongs.
$ id -G
Display All Groups to Which the User Belongs as a Name
You can use the “
-g“, or “
-G” flags with the “
-n” or “
--name” flag to print the user information as a name instead of a number.
For example, the following command will list all the groups to which the user belongs by name.
$ id -nG
I hope you enjoyed reading this article.
If you have any questions, feel free to ask them in the comment section.