How the Linux id Command Displays User and Group Info
The id command in Linux is a fundamental utility used to
query and display real and effective user identity (UID) and group
identity (GID) information. This guide explains the core functionality
of the id command, breaks down its default output, covers
essential command-line options for filtering details, and describes how
the operating system retrieves identity data from system databases.
Basic Usage and Default Output
Running the id command without any arguments outputs the
identity information for the currently logged-in user. You can also
inspect another account by appending the target username:
id
id usernameWhen executed, the utility produces a single line of structured key-value pairs formatted as follows:
uid=1000(john) gid=1000(john) groups=1000(john),4(adm),24(cdrom),27(sudo)
The output contains three primary fields:
uid(User ID): Displays the numeric user identifier followed by the associated username in parentheses. A UID of0indicates the root user, while standard non-system accounts typically begin at1000.gid(Group ID): Shows the numeric primary group identifier and the primary group name in parentheses. When a user creates a file, this group is typically assigned as the file's owning group by default.groups(Supplementary Groups): Lists a comma-separated inventory of all secondary or supplementary groups the user belongs to, including both the numeric GID and the name for each group. Supplementary groups grant access to system permissions, such as administrative access (sudoorwheel).
Common Options and Flags
By default, id outputs all identity data simultaneously.
Specific flags allow administrators and shell scripts to isolate
individual values.
Print Only User ID (
-u):id -uoutputs only the numeric UID (e.g.,1000).- Combining it with
-n(id -un) outputs the resolved username instead of the number.
Print Only Primary Group ID (
-g):id -goutputs only the primary numeric GID.- Combining it with
-n(id -gn) returns only the primary group name.
Print All Supplementary Groups (
-G):id -Glists all numeric group IDs the user belongs to, separated by spaces.- Combining it with
-n(id -Gn) lists all group names instead of numeric IDs.
Real vs. Effective IDs (
-r):- In situations involving
setuidorsetgidexecutables, a process may possess both a "real" ID (the user who ran the command) and an "effective" ID (the identity determining current access permissions). Passing the-rflag forcesidto print the real ID instead of the effective one.
- In situations involving
Security Context (
-Z):- On systems with SELinux or AppArmor enabled,
id -Zoutputs the current process security context (e.g.,unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023).
- On systems with SELinux or AppArmor enabled,
How Linux Resolves Identity Information
The id command does not store identity records
internally. Instead, it interfaces with the Linux Name Service Switch
(NSS) configuration defined in /etc/nsswitch.conf.
For standard standalone systems, id parses local
configuration files:
/etc/passwdto resolve UIDs and usernames./etc/groupto resolve primary and supplementary GIDs and group names.
In enterprise or networked environments, the id utility
transparently queries network directories—such as LDAP, Active
Directory, or FreeIPA—via system daemons like SSSD or Winbind, providing
identical output regardless of where user credentials originate.