id Command

Purpose

Displays the system identifications of a specified user.

Syntax

id [user]

id - G [ -n ] [ User ]

id -g [ -n l | [ -n -r ] [ User ]

id -u [ -n l | [ -n r ] [ User ]

Description

The id command writes to standard output a message containing the system identifications (ID) for a specified user. The system IDs are numbers which identify users and user groups to the system. The id command writes the following information, when applicable:

The id command also writes effective user and group IDs, but only for the user that invoked the id command. (If the User parameter is specified with the id command, the effective IDs are assumed to be identical to real IDs.) If the effective and real IDs for the invoking user are different, the id command writes the following effective ID information, when applicable:

The id command, when specified with the -l option, displays login UID. Login ID indicates the system credentials at the time of logging in to the session. Login UID indicates the user ID (numeric value) of the user, who actually logged in. The login UID is equal to the UID for a user who has logged in to the system and whose credentials remain unchanged. For example, when the user runs the su command, the UID for the user changes and the login UID remains the same.

The id command will fail if the specified user does not exist or if the command cannot read the user or group information.

Flags

The contents and format of the message written by the id command can be altered with the following flags:

Item Description
-G Specifies that the id command write the effective, real, and supplementary group IDs only. If there are multiple entries for the effective, real, or supplementary IDs, they are separated by a space and placed on the same line.
-g Specifies that the id command write only the effective group ID.
-u Specifies that the id command write only the effective user ID.
-r Specifies that the id command write the real ID instead of the effective ID. This flag can be invoked with either the -g flag to write the real group ID, or the -u flag to write the real user ID.
-n Specifies that the id command outputs the name, instead of the ID number, when it is specified with the -G, -g, and -u flags.
-l Specifies that the id command write the login ID instead of the real or effective ID. This flag can be invoked with either the -u flag to write the login UID or the -g flag to write the primary group ID for the login user. When username is passed with the -l option, the id command displays the ID details of the user name instead of the login ID details.
User Specifies the login name of a user for the id command. If no user is specified, the user invoking the id command is the default.

Security

Access Control: This program should be installed as a normal user program in the Trusted Computing Base.

Exit Status

This command returns the following exit values:

Item Description
0 Successful completion.
>0 An error occurred.

Examples

  1. To display all system identifications for the current user, enter:
    id
    Output for the id command is displayed in the following format:
    uid=1544(sah) gid=300(build) euid=0(root) egid=9(printq) groups=0(system),10(audit)
    In this example, the user has user name sah with an ID number of 1544; a primary group name of build with an ID number of 300; an effective user name of root with an ID number of 0; an effective group name of printq with an ID number of 9; and two supplementary group names of system and audit, with ID numbers 0 and 10, respectively.
  2. To display all group ID numbers for the current user, enter:
    id -G
    Output is displayed in the following format:
    0 10 300 9
    The -G flag writes only the group IDs for a user. In this example, user sah is a member of the system (0), audit (10), build (300), and printq (9) groups.
  3. To display all group names for the current user, enter:
    id -Gn
    Output is displayed in the following format:
    system audit build printq
    The -n flag writes only the names instead of the ID numbers.
  4. To display the real group name for the current user, enter:
    id -gnr
    Output is displayed in the following format:
    build
  5. To display the login UID after logging in as root and running the su command to user sah, type:
    id -lu
    Output is displayed in the following format:
    0
  6. To display the primary group name of the user who actually logged in, type:
    id -lgn
    Output is displayed in the following format:
    system
  7. To display the primary group ID of the user who actually logged in, type:
    id -lg
    Output is displayed in the following format:
    0

Files

Item Description
/usr/bin/id Contains the id command.