Linux I d command: 5 Practical examples

Linux I d command: 5 Practical examples


The id command in Linux is used for displaying the actual and efficient consumer ID and group ID of a consumer.

On this tutorial, I am going to present you how you can use id command in Linux with a few of the most typical and helpful examples.

id command in Linux

That is the syntax for the id command:

id [options] [username]

When you do not present a username, the command shows the main points concerning the at present logged-in consumer.


Here is the output it displayed for me in Ubuntu Linux.

[email protected]:~$ id
uid=1000(abhishek) gid=1000(abhishek) teams=1000(abhishek),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),119(lpadmin),130(lxd),131(sambashare)

Within the above output, consumer abhishek has uid 1000 and gid 1000. That is the first group the consumer abhishek belongs to by default.

Aside from that, the consumer abhishek can be member of sure different teams and people teams have additionally been displayed within the output.

Examples of id command

Listed below are the commonest choices for the id command:

Choice Description
-u Print the efficient consumer id
-g Print the efficient group id
-G Print the IDs of all teams consumer belongs to
-n Print names as an alternative of IDs (have to be mixed with -u, -g or -G)
-r Print actual ID as an alternative of efficient IDs (have to be mixed with -u, -g or -G)

Actual vs Efficient consumer and group ID?

This could possibly be complicated for you. When a consumer is created, it’s given a username, a consumer ID (uid), a default group and the id of that default group is the gid for that consumer. That is the ‘actual’ consumer and group ID.

Since in Linux, processes could be run as different consumer and group, there may be additionally a second set of IDs referred to as efficient IDs.

More often than not the actual and efficient UIDs and GIDs are the identical. However there are conditions when an everyday consumer has to change a privileged file. That is the place the efficient ID idea is used. Commonest instance is the utilizing passwd command to vary the password which modifies the /and many others/passwd file owned by root.

I can’t go intimately right here however I like to recommend studying about it right here. You must also examine SUID, GUID and sticky bit permissions in Linux.

1. Print the UID and GID of a sure consumer

To print the uid and gid and all the opposite group IDs of a consumer, you simply need to specify the username:

id username

You possibly can record all of the customers in your Linux system to get the specified consumer identify.

What’s UID in Linux? Methods to Discover UID of a Consumer?

This Linux Fundamentals information teaches you the whole lot necessary related to UID in Linux.

Linux I d command: 5 Practical examples

2. Print solely the UID of a consumer

You need to use the -u choice to print the UID in Linux. As talked about beforehand, when you omit the username, it shows the details about the logged-in consumer.

id -u userame

Take into account that it shows solely the UID, the numeric worth, not the identify.

[email protected]:~$ id -u

3. Print solely the GID of a consumer

Equally, you should utilize the choice -g to print the GID of a consumer. After I say GID, it is the numeric ID of the default group the consumer belongs to.

id -g username

Once more, it can solely show the numeric ID of the group.

[email protected]:~$ id -g no one

4. Print the IDs of all different teams the consumer belongs to

A consumer can belong to a number of teams. That is primary function of the Linux filesystem. You need to use the usermod command and add it to sudo group to provide it root privileges.

You need to use the -G choice to show the IDs of all of the teams the consumer belongs to.

id -G username

This too shows the ID solely.

[email protected]:~$ id -G abhishek
1000 4 24 27 30 46 119 130 131

5. Print names as an alternative of the numeric IDs

The numeric IDs solely could be complicated. If you would like the names, you may mix the -n choice with -u, -g or -G to show the names.

For instance, if you wish to show all of the teams a consumer belongs to, you should utilize it like this:

id -nG username

If I take advantage of the earlier instance with choice -n here is what it reveals:

[email protected]:~$ id -nG abhishek
abhishek adm cdrom sudo dip plugdev lpadmin lxd sambashare

Bonus Tip: Print the actual IDs

All of the above examples show the efficient IDs. Nearly on a regular basis it is going to be the actual ID.

Nevertheless, if you wish to be sure to get the actual ID, you may mix choice -r with -u, -g or -G.

It may be used like this:

id -ru username

Alright! I feel you realize sufficient concerning the id command now. In case you have questions or options, be happy to depart a remark.

linux id command ldap,get group id linux,whoami command in linux,w command in linux,useradd command in linux,who command in linux,linux find username from id,finger command in linux

More Stories
Cloud Series: Authorize anything with macaroons