Linux id Command: Show User and Group IDs

id checks the user ID (UID), default group ID (GID), and supplementary groups of the current process or a specified user. It is a starting point for verifying the actual group information of the current account when checking file access permissions.

When run without arguments, it prints the user and group information of the current process. If a user is specified, it looks up that user's information in the account database. For processes where the effective UID and original UID differ, -r can be used to separately check the original ID.

Basic syntax

id [option] [user]

The installed implementation and options may vary depending on the distribution. Check the description on your system with man id.

Examples

Check current user and group

Displays UID, default GID, and supplementary groups together.

id

Query another account

The group composition of the account can be queried, but permission is not switched to that account.

id alice

Extract only names or numbers

-u prints the valid UID, -un prints the corresponding name.

id -u
id -un

Reading UID, GID, and supplementary groups

id displays the user identification number (UID), primary group number (GID), and supplementary groups all at once. The numbers and names vary by system.

id

Example output:

uid=1000(alice) gid=1000(alice) groups=1000(alice),27(sudo)

In this example, alice's primary group is shown after gid=, not next to the UID. Supplementary groups affect file access permissions and administrator rights. If a script only needs the numeric UID, use id -u; if you only need the current user's group names, use id -Gn.

Main Options and Format

Options/Format Description
-u Displays only the user ID.
-g Displays only the valid primary group ID.
-G Displays all group IDs.
-n Displays as names with -u, -g, -G.
-r Displays the real ID instead of the valid ID with -u, -g, -G.

Precautions when using

If you have just changed the user's group membership, the list of groups in an already open login session may differ from the results of a query to the account database. When investigating permission issues, run id directly in the session where the problem occurred. id alice does not change the privileges of the current session.

Frequently Asked Questions

What are the UID and GID displayed in id?

UID is the user identification number, and GID is the primary group identification number. Additional groups are displayed in the groups entry that follows.

Official Documentation

The exact behavior of the options and differences between implementations can be checked in the official documentation related to id.