Linux id Command Tutorial for Beginners (5 Examples)

If you are new to system administration in Linux, you'll gradually learn that user management is an important aspect of your work. The Linux command line offers several command-line utilities for this purpose, and one of them is the id command.

In this article, we will discuss the basics of this tool using some easy to understand examples. However, before that, it's worth mentioning that all examples in this tutorial have been tested on an Ubuntu 16.04 LTS machine.

Linux id command

The id command shows you the real and effective user and group IDs. Following is its syntax:

id [OPTION]... [USERNAME]

And here's how the tool's man page explains it:

Print user and group information for the specified USERNAME, or (when USERNAME omitted) for the current user.

Following are some Q&A-styled examples that should give you a good idea on how the id command works.

In case you aren't aware of what real and effective IDs are, read the discussion here.

Q1. How to use id command?

The basic usage is easy - all you have to do is to execute 'id' with the username for which you want to access the information. For example:

id himanshu

How to use id command?

So you can see the output consists of several fields. The first two entries are user and group IDs for 'himanshu', while the rest are the groups that the user 'himanshu' is part of, along with the respective group IDs.

Note that if you don't pass any username as an argument to the id command, the tool assumes the current user as the one for which you want the information.

Q2. How to make id print only group IDs?

This can be achieved using the -G command line option. For example:

id -G himanshu

How to make id print only group IDs?

So you can see that only group IDs were displayed in the output.

Q3. How to make id print only effective group ID?

This can be achieved using the -g command line option. For example:

id -g himanshu

How to make id print only effective group ID

Q4. How to make id print only effective user ID?

Similar to the previous example, this can be achieved using the -u command line option. For example:

id -u himanshu

How to make id print only effective user ID

Q5. How to make id print real IDs instead of effective IDs?

To make the id command print real IDs, use the -r command line option. This option can be clubbed with the -u, -g, and -G command line options.

For example:

id -ur himanshu

Conclusion

The id command is easy to understand and use. The number of command line options it offers is also limited, and we've discussed the majority of them here. Once you are done practicing these, head to the tool's man page to learn more about it.

Himanshu Arora

About Himanshu Arora

Himanshu Arora has been working on Linux since 2007. He carries professional experience in system level programming, networking protocols, and command line. In addition to HowtoForge, Himanshu's work has also been featured in some of world's other leading publications including Computerworld, IBM DeveloperWorks, and Linux Journal.

Share this page:

Suggested articles

1 Comment(s)

Add comment

Comments

By: Emre at: 2018-04-24 14:01:12

Good article! Thank you!