Linux / Unix id Command Examples nixCraft Updated Tutorials/Posts

I am a new Linux and Unix system user. How do I find out the user and groups names and numeric IDs of the current user or any users on my server? How can I display and effective IDs on the system using command line options? In Linux, how do I find a user’s UID or GID?To find a user’s UID (user ID) or GID (group ID) and other information in Linux/Unix-like operating systems, use the id command.

This command is useful to find out the following information:

Get User name and real user ID

Find a specific user’s UID

List out all the groups a user belongs to

Show the UID and all groups associated with a user

Display security context of the current user

Effective Linux or Unix user name and effective user ID (UID)

Name of effective Linux or Unix user’s group and effective group ID (GID)

Purpose

Displays the system identifications of a specified user.

id command syntax

The basic syntax is:

idid [UserNameHere]id [options]id [options] [UserNameHere]

By default id command shows the the user and group names and numeric IDs, of the calling process i.e. the current user who runs the id command on screen. If a login name or user ID ([UserNameHere]) given on command line, the user and group IDs of that user are displayed.

Linux / Unix id command examples

Let us see how to find a user’s UID or GID on Linux or Unix-like operating systems using 13 id command practical examples. First, open the Terminal application and then type:

Find out all the groups a user belongs to…

In this example, display the UID and all groups associated (secondary groups) with a user called ‘vivek’, run:id -G {UserNameHere}id -G vivekSample outputs

20 12 61 79 80 81 98 33 100 204 398 399

Display a name instead of a UID/GID

By default, id command displays number for the -G, -g and -u options. You can force id command to display the name of the UID or GID instead of the number for the -G, -g and -u options by passing the -n option as follows:id -ng {UserNameHere}id -nu {UserNameHere}id -nG {UserNameHere}id -nG vivekSample outputs:

Related media

See also

Get 15% off on Linux Foundation certified SysAdmin, Progamming, Kubernetes/Containers and Open Stack certification & course. Use “CYBER15” coupon code.training.linuxfoundation.org

Posted by:Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.