id Command in Linux with Examples

This tutorial explains Linux “id” command, options and its usage with examples.

id – print real and effective UIDs and GIDs

Description :

This command is useful to find out the following information:

1. Find a specific user’s UID.
2. Find a specific user’s UID.
3. Find out all the groups a user belongs to.
4. Find the UID and all groups associated with a user.
5. Display security context of the current user.

Usage :

id [OPTION]… [USERNAME]

advertisement
advertisement

Options :

-a
ignore, for compatibility with other versions
-g, –group
print only the effective group ID
-G, –groups
print all group IDs
-n, –name
print a name instead of a number, for -ugG
-r, –real
print the real ID instead of the effective ID, with -ugG
-u, –user
print only the effective user ID
–help
display this help and exit

Examples :

1. To display all system identifications for the current user, enter:

Note: Join free Sanfoundry classes at Telegram or Youtube
$ id
uid=1544(abc) gid=300(abc) groups=0(system),10(audit)

2. Find a specific user’s UID

In this example, find abc’s UID, type:

$ id -u vivek
1544

3. Find a specific user’s GID

advertisement

In this example, find a abc’s GID, run:

$ id -g vivek
300

4. How do I see the UID and all groups associated with a user name?

In this example, find the UID and all groups associated with a user called ‘root’, enter:

$ id root
uid=0(root) gid=0(wheel) groups=0(wheel),1(daemon),2(kmem),3(sys),4(tty),5(operator),8(procview),9(procmod),12(everyone),20(staff),29(certusers),61(localaccounts),80(admin),33(_appstore),98(_lpadmin),100(_lpoperator),204(_developer),398(com.apple.access_screensharing),399(com.apple.access_ssh)

5. Find out all the groups a user belongs to…

advertisement

In this example, display the UID and all groups associated (secondary groups) with a user called ‘abc’, run:

$ id -G abc
20 12 61 79 80 81 98 33 100 204 398 399

6. 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 abc
staff everyone localaccounts _appserverusr admin _appserveradm _lpadmin _appstore _lpoperator _developer com.apple.access_screensharing com.apple.access_ssh

7. How do I display real ID instead of the effective ID for specified user?

You can show the real ID for the -g, -G and -u options instead of the effective ID by passing the -r option:

$ id -r -u abc
501

Sanfoundry Global Education & Learning Series – 1000 Linux Tutorials.

If you wish to look at all Linux commands and their usage examples, go to Linux Commands Tutorial.

If you find any mistake above, kindly email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.