id Command in Linux: Display User and Group Information

When a command fails with a “Permission denied” error, the first thing to check is which account you are running as and which groups you belong to. The id command prints this information. It shows the real and effective user and group IDs, along with the supplemental groups that grant you additional permissions.
This article covers the id command syntax, its options, and practical examples of using it in everyday administration and shell scripts.
Using the id Command
The syntax for the id command is as follows:
id [OPTIONS] [USER]...If the username is omitted, id displays information about the user running the command.
When invoked without any option, id prints the real user ID (uid), the user’s real primary group ID (gid), and real IDs of the supplemental groups (groups) the user belongs to. Effective IDs are printed only when they differ from the real ones.
iduid=1000(linuxize) gid=1000(linuxize) groups=1000(linuxize),4(adm),27(sudo),998(docker)If SELinux is enabled, id also prints the user’s security context (context):
uid=1000(linuxize) gid=1000(linuxize) groups=1000(linuxize) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023To obtain information about another user, pass the username or user ID as an argument:
id markuid=1001(mark) gid=1001(mark) groups=1001(mark),998(docker)To display information about several users at once, pass their names as arguments:
id root markuid=0(root) gid=0(root) groups=0(root)
uid=1001(mark) gid=1001(mark) groups=1001(mark),998(docker)Each user is printed on a separate line, in the order you listed them.
When a user with a name identical to the supplied numeric ID exists on the system, the name lookup takes precedence. Prefix the ID with the + symbol to force numeric lookup.
For example, if you have a user with name 1010 and another user with ID 1010, running id 1010 will display information about the user whose name is 1010. To query the user with UID 1010 instead, run id +1010. Tools such as useradd reject all-numeric user names by default, so you will rarely run into this.
id Command Options
The id command accepts several options that limit output to a specific field. These are especially useful in shell scripts where you need a single value rather than the full line.
Print User ID
The -u (--user) option prints only the effective user ID:
id -u1000Print Primary Group ID
The -g (--group) option prints only the effective primary group ID:
id -g1000Print All Group IDs
The -G (--groups) option prints the IDs of every group the user belongs to, including the primary group and all supplemental groups
:
id -G1000 4 27 998Print Names Instead of Numbers
The -n (--name) option prints names instead of numeric IDs. It must be combined with -u, -g, or -G:
id -unlinuxizeRunning id -un produces the same output as the whoami
command, and id -Gn is equivalent to the groups command.
Print Real IDs
The -r (--real) option prints real IDs instead of effective ones. Like -n, it must be combined with -u, -g, or -G:
id -ur1000In most situations the real and effective IDs are the same. They diverge when a process runs under a setuid or setgid binary. In that case, the default id output includes an extra euid or egid field:
uid=1000(linuxize) gid=1000(linuxize) euid=0(root) groups=1000(linuxize)The euid=0(root) field shows that the process runs with the effective user ID of root. Here, id -u prints 0. The id -ur command still prints 1000.
Print SELinux Context
The -Z (--context) option prints the security context of the current process:
id -Zunconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023If SELinux is disabled
, id prints an error message:
id: --context (-Z) works only on an SELinux-enabled kernelOn Ubuntu 25.10 and later, id comes from the Rust-based coreutils. The message there ends with works only on an SELinux/SMACK-enabled kernel.
The security context belongs to the current process, so -Z does not accept a username. Running id -Z mark prints id: cannot print security context when user specified.
NUL-Delimited Output
The -z (--zero) option separates output items with a NUL character instead of whitespace, which is useful when piping into tools like xargs -0:
id -zGThe -z option is not permitted in the default output format. Combine it with -u, -g, -G, or -Z. On its own, it prints id: option --zero not permitted in default format.
Using id in Scripts
The id command is commonly used in shell scripts to verify permissions before running privileged operations.
Check whether the current user is root:
if [ "$(id -u)" -eq 0 ]; then
echo "Running as root"
else
echo "This script requires root privileges"
exit 1
fiCheck whether the current user belongs to the docker group:
if id -Gn | tr ' ' '\n' | grep -qx docker; then
echo "User is in the docker group"
else
echo "User is not in the docker group"
fiThe tr command puts each group name on its own line, and grep -x matches only whole lines. A plain grep -w docker also matches a group named docker-users. The hyphen counts as a word boundary.
Store the current username in a variable for logging:
CURRENT_USER="$(id -un)"
echo "Script started by $CURRENT_USER"Quick Reference
| Option | Description |
|---|---|
-u (--user) | Print effective user ID |
-g (--group) | Print effective primary group ID |
-G (--groups) | Print all group IDs |
-n (--name) | Print names instead of numbers (combine with -u, -g, or -G) |
-r (--real) | Print real IDs instead of effective (combine with -u, -g, or -G) |
-Z (--context) | Print SELinux security context |
-z (--zero) | NUL-delimit output instead of whitespace |
Troubleshooting
A new group does not appear in id output
Without a username, id prints the groups of the current process. Linux assigns those groups when the session starts. After you add a user to a group with usermod -aG, run id username to confirm the change, then log out and log back in. To use the new group without logging out, start a shell with newgrp groupname. For more details, see our guide on how to add a user to a group
.
id: printing only names or real IDs requires -u, -g, or -G
The -n and -r options change how a single field is printed, so id rejects them in the default output. Add -u, -g, or -G, for example id -un or id -Gn.
FAQ
What is the difference between real and effective user ID?
The real user ID is the account that started the process. The effective user ID is the identity the kernel uses for permission checks. They are usually the same, but they can differ when a setuid binary (such as passwd or sudo) temporarily elevates privileges.
How do I check if a user belongs to a specific group?
Run id -Gn username to list all group names, then pipe the output through tr and grep -qx groupname to check for an exact match. For example: id -Gn mark | tr ' ' '\n' | grep -qx docker.
What is the difference between id and whoami?
The whoami command prints only the effective username, which is equivalent to id -un. The id command provides more detail, including numeric IDs and all group memberships.
Conclusion
The id command displays user and group identity for any account on the system. For related tasks, see how to create users
, manage groups
, or list group memberships
.
Tags
Linuxize Weekly Newsletter
A quick weekly roundup of new tutorials, news, and tips.
About the authors

Dejan Panovski
Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 1000+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.
View author page