id command in Linux with examples
id command in Linux is used to find out user and group names and numeric ID’s (UID or group ID) of the current user or any other user in the server. This command is useful to find out the following information as listed below:
- User name and real user id.
- Find out the specific Users UID.
- Show the UID and all groups associated with a user.
- List out all the groups a user belongs to.
- Display security context of the current user.
id [OPTION]… [USER]
- -g : Print only the effective group id.
- -G : Print all Group ID’s.
- -n : Prints name instead of number.
- -r : Prints real ID instead of numbers.
- -u : Prints only the effective user ID.
- –help : Display help messages and exit.
- –version : Display the version information and exit.
Note: Without any OPTION it prints every set of identified information i.e. numeric ID’s.
- To print your own id without any Options:
The output shows the ID of current user UID and GID.
- To find a specific users id: Now assume that we have a user named master, to find his UID we will use the command:
id -u master
- To find a specific users GID: Again assuming to find GID of master, we will use the command:
id -g master
- To find out UID and all groups associated with a username: In this case we will use the user “master” to find UID and all groups associated with it, use command:
- To find out all the groups a user belongs to: Displaying the UID and all groups a user “master” belongs to:
id -G master
- To display a name instead of numbers: By default the id command shows us the UDI and GID in numbers which a user may not understand, with use of -n option with -u, -g and -G, use command(s)
id -ng master or id -nu master or id -nG master
- To display real id instead of effective id: To show the real id with the use of -r option with -g, -u and -G, use command(s):
id -r -g master id -r -u master id -r -G master