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:
Print the efficient consumer id
Print the efficient group id
Print the IDs of all teams consumer belongs to
Print names as an alternative of IDs (have to be mixed with -u, -g or -G)
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:
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.
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.