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 18.04 LTS machine and Debian 10.
Linux id command
The id command shows you the real and the effective user and group IDs of a given user. 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.
The 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:
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
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
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
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 combined with the -u, -g, and -G command-line options.
id -ur himanshu
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.