How to View User and Group IDs Using the id Command in Linux

When you log into a Linux server (especially one managed by a central directory service like LDAP or Active Directory), simply knowing your username is not enough. The Linux kernel does not actually care about your human-readable name; it manages permissions and file ownership using strict numeric identifiers. To see exactly who you are, what your numeric ID is, and every single security group you currently belong to, you must use the id command.

How to Use the id Command

The id command requires zero configuration and zero administrative privileges. It is purely an informational tool that queries the /etc/passwd and /etc/group databases.

Simply open your terminal and type:

id

When you press Enter, the terminal will output a single, dense line of text containing three distinct pieces of information:

  • uid (User ID): This is your primary identity. The root administrator is always uid=0(root). A standard human user usually starts at 1000 (e.g., uid=1000(john)).
  • gid (Group ID): This is your primary default group. Every file you create will automatically be assigned this group ownership. (e.g., gid=1000(john)).
  • groups: This is a comma-separated list of every supplementary group you belong to. If you are in the sudo group or the docker group, it will be listed here, confirming you have elevated privileges.

How to Query Other Users

You are not restricted to only querying your own identity. If you are auditing a system and need to verify the permissions of a specific service account (like the Apache web server user), you can pass that username directly to the command as an argument.

id www-data

The command will instantly output the exact User ID and Group ID of the www-data account, proving exactly what groups the web server is allowed to access.

Formatting the Output for Bash Scripts

If you are writing an automated bash script that must verify if the person running the script is the root administrator, parsing the dense, comma-separated default output of the id command is highly inefficient. You can use specific flags to force the command to output only raw, mathematical integers.

  • To print only your raw numeric User ID (e.g., outputting just 1000), run: id -u
  • To print only your raw numeric primary Group ID, run: id -g
  • To print only the human-readable username of the person currently logged in, run: id -un

These highly targeted flags are perfect for embedding into if/then statements within complex deployment scripts.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.