Beginners Guide for ID Command in Linux

Linux TLDR
Last Updated:
Reading time: 2 minutes

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

DescriptionID (Identity)
Difficulty LevelLow
Root or Sudo PrivilegesNo
OS CompatibilityUbuntu, Manjaro, Fedora, etc.
Prerequisitesid
Internet RequiredNo

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:

id command output

To get information about different users, specify their username with the id command.

$ id jake

Output:

Checking different user information

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:

Printing the current logged-in user UID

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:

Printing the current logged-in user GID

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:

Printing the user real UID and GID

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:

Printing all the GID to which user belong to

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:

Printing all the groups to which user belong

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.