NAME
id —
get credentials
SYNOPSIS
id |
[user]… |
id |
-u|-g|-G
[-nrz] [user]… |
id |
-Z [-z] |
groups |
[user]… |
whoami |
DESCRIPTION
The flag-free form writes users' (each of which can either be a name or a numeric ID; if none specified — the process') credentials to the standard output stream:
The IDs listed are real; euid= and egid=, containing the effective IDs, are only written if they differ.
If one of -ugGZ is specified, the IDs are
effective by default, and only the specified field is output, numerically.
For example, those very same invocations, but with
-G and -u respectively:
0 10 220-rn:
root wheel 22cicadaThe set of supplementary groups is sorted, but always starts with the primary group.
An unknown user is not a fatal error — a diagnostic is issued and processing continues.
The mandatory access control context is omitted from the default
format if unavailable or unset, and -Z is forbidden
if it's unavailable; additionally, as it's a property of the process, not
user, it's only available if no user was
specified.
groupsis equivalent toid-Gn.whoamiis equivalent toid-un.
OPTIONS
-u,--user- Write just the user ID.
-g,--group- Write just the primary group ID.
-G,--groups- Write just the secondary group IDs.
-Z,--context- Write just the security context.
-n,--name- Write the specified field as a human-readable name, rather than numerical ID.
-r,--real- Use the real user or primary group ID of the process, rather than the effective one. No effect with users.
-z,--zero- Terminate each entry with a NUL character, rather than a single space or newline.
-a- Ignored for compatibility with the illumos gate, whose default
idrequires it to write the supplementary groups. (But the version from AT&T research dated 2004 also just ignores it.)
EXIT STATUS
1 if at least one user or group wasn't on file.
SEE ALSO
who(1), getegid(2), getgroups(2), getuid(2), getgrouplist(3), getgwgid(3), getpwuid(3), selinux(8)
STANDARDS
id conforms to IEEE Std
1003.1-2024 (“POSIX.1”).
Mandatory access control behaviour (-Z,
context=) is compatible with the GNU system, though the
latter deviates from the standard if a context is present; this is not
considered a problem, as -ugG is recommended by the
standard for noninteractive use, and scripts relying on the default
CB-UNIX-style output already filter it.
-za and multiple
users are extensions, also present on the GNU
system.
The ordering of supplementary groups is not guaranteed.
HISTORY
whoami first appeared in
2BSD as
whoami(UCB), noting:
groups appeared in
4.1cBSD as
groups(1):
4.2BSD allows one user, as present-day.
id first appeared in CB-UNIX at or before
version 2.1, using the familiar
4.4BSD was the first to include
id, quoting conformance with IEEE
Std 1003.2 (“POSIX.2”), including the
-p extension, deprecating
groups and whoami, replacing
them with shell wrappers.
Since coreutils 8.31 (2019-03-10), the GNU system allows multiple
users for id, too.