LinuxCommandLibrary

id

Display user and group identification numbers

TLDR

Display current user's ID (UID), group ID (GID) and groups to which they belong

$ id
copy

Display the current user identity
$ id [[-un|--user --name]]
copy

Display the current user identity as a number
$ id [[-u|--user]]
copy

Display the current primary group identity
$ id [[-gn|--group --name]]
copy

Display the current primary group identity as a number
$ id [[-g|--group]]
copy

Display an arbitrary user's ID (UID), group ID (GID) and groups to which they belong
$ id [username]
copy

SYNOPSIS

id [OPTION]... [USER]

PARAMETERS

-g
    Print only the effective group ID.

-G
    Print all group IDs, separated by spaces.

-n
    Print a name instead of a number, for -u, -g or -G options.

-r
    Print the real ID as opposed to the effective ID, for -u, -g or -G options.

-u
    Print only the effective user ID.

-z
    Separate entries with NUL characters, not whitespace. Does not replace the default last separator.

--help
    Display help and exit.

--version
    Output version information and exit.

DESCRIPTION

The id command in Linux displays user and group information for the specified user, or the current user if no user name is provided. It outputs the user ID (UID), group ID (GID), and a list of supplementary group IDs. This information is essential for understanding the user's permissions and access rights within the system. The command provides various options to control the output format, such as displaying only the UID, GID, or a list of groups.

It can be used to quickly verify the effective identity of a user or process, or to determine which groups a user belongs to. This information is crucial for system administrators to troubleshoot access issues and manage user permissions effectively. The id command is a fundamental tool for user and group management in Linux environments.

CAVEATS

The displayed group IDs may not reflect all groups a user is effectively a member of, especially when using directory services like LDAP or Active Directory, which may require additional tools for full group membership enumeration. The '-z' parameter is useful for scripting purposes where whitespace might be problematic in the output.

SECURITY CONSIDERATIONS

When used in scripts, be mindful of the user context in which the script runs. Elevated privileges (e.g., running as root) will alter the output of the id command and potentially affect script behavior. Sanitize any input if a user name is being passed dynamically to the id command to avoid potential command injection vulnerabilities.

USAGE EXAMPLES

id: Displays information about the current user.
id username: Displays information about the specified user.
id -u: Displays only the user ID.
id -g: Displays only the group ID.
id -nG: Displays group names instead of group IDs.

HISTORY

The id command is a relatively old and ubiquitous command, dating back to early versions of Unix. It has been a standard part of POSIX and Linux distributions for a long time. The core functionality has remained largely consistent, with minor additions to enhance output formatting and security considerations. The purpose was always to quickly provide the identity information of a user within the system.

SEE ALSO

groups(1), whoami(1), logname(1), getent(1)

Copied to clipboard