id

user managementLinux/Unix
The id command is one of the most frequently used commands in Linux/Unix-like operating systems. id Display user identity information

Quick Reference

Command Name:

id

Category:

user management

Platform:

Linux/Unix

Basic Usage:

id [options] [arguments]

Common Use Cases

    Syntax

    id [options] [username]

    Options

    Option Description
    -u, --user Print only the effective user ID
    -g, --group Print only the effective group ID
    -G, --groups Print all group IDs
    -n, --name Print a name instead of a number (with -ugG)
    -r, --real Print the real ID instead of the effective ID (with -ugG)
    -z, --zero Delimit entries with NULL characters, not whitespace
    -Z, --context Print only the security context (SELinux)
    --help Display help information and exit
    --version Output version information and exit

    Examples

    How to Use These Examples

    The examples below show common ways to use the id command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.

    # Basic Examples Basic
    id
    Display current user's identity information.
    id root
    Display identity information for user 'root'.
    id -u
    Display only the effective user ID. # Advanced Examples Advanced id -g Display only the effective group ID. id -G Display all group IDs. id -n Display names instead of numbers. id -un Display only the username. id -gn Display only the group name. id -Gn Display all group names the user belongs to.

    Try It Yourself

    Practice makes perfect! The best way to learn is by trying these examples on your own system with real files.

    Understanding Syntax

    Pay attention to the syntax coloring: commands, options, and file paths are highlighted differently.

    Notes

    The id command displays user and group identity information in Unix and Linux systems. It provides a concise way to determine the numeric user ID, group ID, and group memberships of a user, which is crucial for understanding permissions and access rights. Key features of id: 1. User Identification: id displays the user ID (UID) of the current user or a specified user, which is essential for identifying who is executing commands or accessing resources. 2. Group Identification: The command shows both the primary group ID (GID) and all supplementary groups a user belongs to, which affects file access permissions and resource availability. 3. Name Resolution: By default, id displays both numeric IDs and their corresponding names, making it easier to interpret the output. The -n option can be used to display only names. 4. Selective Output: Various options allow focusing on specific aspects of user identity, such as only the user ID (-u), group ID (-g), or all groups (-G), which is useful for scripts and specific queries. 5. Real vs. Effective IDs: id can distinguish between real and effective user/group IDs (with the -r option), which is important in contexts where processes change their identity temporarily. 6. Security Context: On systems with SELinux, the -Z option displays the security context of a user, providing information about the security policy constraints. 7. Cross-User Queries: When run with superuser privileges, id can display identity information for any user on the system, not just the current user. The id command is commonly used in: - Shell scripts that need to check user identity or group membership - Troubleshooting permission issues - Verifying user account configuration - Security auditing - Understanding the security context of processes In modern Linux systems, id is a fundamental tool for user identity management and plays a crucial role in the overall security architecture. It helps administrators and users understand the complex relationships between users, groups, and permissions that form the basis of Unix-style access control.

    Related Commands

    These commands are frequently used alongside id or serve similar purposes:

    Use Cases

    Learn By Doing

    The best way to learn Linux commands is by practicing. Try out these examples in your terminal to build muscle memory and understand how the id command works in different scenarios.

    $ id
    View All Commands