Id command in Linux
3 min read
id is a command-line utility that prints the real and effective user and group IDs.
The syntax for the
id command is as follows:
id [OPTIONS] [USERNAME]
If the username is omitted, the
id command displays information about the currently logged-in user.
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 user ID, group ID, and supplemental group IDs are printed only when they are different from the real ones.
uid=1000(linuxize) gid=1000(linuxize) groups=1000(linuxize),4(adm),27(sudo),998(docker)
If SELinux is enabled, then
id also prints the user’s security context (
uid=1000(linuxize) gid=1000(linuxize) groups=1000(linuxize) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
To obtain information about another user, pass the username or user ID as an argument to the
uid=1001(mark) gid=1001(mark) groups=1001(mark),998(docker)
In case when a user with a name same as the supplied ID exists on the system, the name look-up is taking precedence. When using the user ID as an argument, prefix the ID with the
+ symbol to avoid interpreting the ID as a name.
For example, if you have a user with name
1010 and another user with ID
1010, if you type
id 1010 the command will display information about the user with name
1010. To obtain information about the user with ID
id Command Options
id command accepts several options that allow you to display only specific information. This is useful when using
id in shell scripts.
To print only the effective user ID, use the
--group) option tells
id to print only the effective group ID:
1000 4 27 998
--groups) option to print effective IDs of all groups the user belongs
To print names instead of numbers use the
--name option. This option can be used only in combination with
id command with the
-un options produce the same output as running
, and the output of
id -Gn is equivalent to the output of the
--real) option can be used in combination with
-G to print the real, instead of effective values:
To print only the security context of the process, which is usually the user’s security context, use the
If SELinux is disabled
id prints an error message:
id: --context (-Z) works only on an SELinux-enabled kernel
--zero) option tells
id to delimit the output items with the NUL character, not whitespace:
This can be useful when piping the output to a command that can parse newlines
id command prints information about a given user, or the currently logged in user if no user name or ID is provided as an argument.
Feel free to leave a comment if you have any questions.