Home > Environment & Utility > id

id: Print User and Group ID Information

The `id` command prints the user ID (UID), group ID (GID), and all supplementary group information for the current logged-in user or a specified user. It is a fundamental command useful for checking user permissions and group memberships.

Overview

`id` is short for 'identity' and displays the numerical IDs used to identify users on the system. Linux systems manage permissions using UID (User ID) and GID (Group ID) instead of usernames. The `id` command outputs the UID, GID, and a list of supplementary groups for the user running the current shell. This allows for quick identification of file and directory access permissions and program execution rights, making it one of the first tools a system administrator uses when troubleshooting user permission issues.

Key Features

Key features of the `id` command include:

  • Prints the UID and GID of the current user or a specified user.
  • Displays a list of all groups a user belongs to.
  • Provides useful information for troubleshooting permission-related issues.
  • Used in scripts to verify user or group IDs.

id-related Terms

Key terms that can be checked with the `id` command.

  • UID (User ID): A unique numerical ID that identifies a user. Typically, 0 is assigned to `root`, 1-999 to system accounts, and 1000+ to regular users.
  • GID (Group ID): A unique numerical ID that identifies a group. A user can belong to one or more groups.
  • groups: A list of all groups a user belongs to. The first group is the 'primary group', and the rest are 'supplementary groups'.

Main Options

Commonly used `id` command options are grouped by their purpose.

1) Output Options

2) Help

Generated command:

Try combining the commands.

Description:

`id` Executes the command.

Combine the above options to virtually execute commands with AI.

Usage Examples

Explore the various uses of the `id` command through these examples.

Print Current User Information

id

Prints the UID, GID, and group membership information for the currently logged-in user.

Print Specific User Information

id guest

Prints detailed information for the user named `guest`.

Print User's UID and GID

id -u
id -g

Prints only the numerical values of the user's UID and primary GID, respectively.

Print Only User Name

id -un

Prints only the name of the current user. Returns the same result as the `whoami` command.

Print All Group Names

id -Gn

Prints the names of all groups a user belongs to, separated by spaces. Similar to the `groups` command.

Installation

`id` is part of the `coreutils` package and is included by default in most Linux distributions. No separate installation is required.

Tips & Cautions

Important points to note when using the `id` command.

Tips

  • Using `id -u` allows you to get the current user's UID, which is useful in scripts to check for root privileges. (e.g., `if [ "$(id -u)" == "0" ]; then ... fi`)
  • The `id -Gn` command produces the same result as the `groups` command. Both commands are convenient for checking which groups a user belongs to.

Related commands

These are commands that are functionally similar or are commonly used together.


Same category commands