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.
Tutorial Details
Description | ID (Identity) |
Difficulty Level | Low |
Root or Sudo Privileges | No |
OS Compatibility | Ubuntu, Manjaro, Fedora, etc. |
Prerequisites | id |
Internet Required | No |
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.
$ id
Output:
To get information about different users, specify their username with the id command.
$ id jake
Output:
Display Current User Identity as a Number
The “-u
” or “--user
” flag is used to display the current user’s identity as a number without a username.
$ id -u
Output:
Display Current Group Identity as a Number
The “-g
” or “--group
” flag is used to display the current group identity as a number.
$ id -g
Output:
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
Output:
Display All Groups IDs to Which the User Belongs as a Number
The “-G
” or “--groups
” flag will print all the group IDs as a number in your system to which the current user belongs.
$ id -G
Output:
Display All Groups to Which the User Belongs as a Name
You can use the “-u
“, “-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
Output:
I hope you enjoyed reading this article.
If you have any questions, feel free to ask them in the comment section.
Join The Conversation
Users are always welcome to leave comments about the articles, whether they are questions, comments, constructive criticism, old information, or notices of typos. Please keep in mind that all comments are moderated according to our comment policy.