Introduction to Linux id
An id is a command-line-utility tool in Linux which is used to find out user and group names and real id’s of the current user or any other user in the server.
It also gives us the list of groups the user is present and displays the current user’s security context when used with different options available for the command. This is mainly used for user management in a server. It is a command to print real and effective UID (user ID) and GID (Group ID). More than one UID in a group is called as GID.
Advantages of id Command in Linux
Id command is used in finding users and group details. Below are a few more useful options to use the id command in Linux.
- To find out the user name and real user id in the system.
- To get specified user id UID.
- To get all the details of UID and group ids of the user.
- To list all the groups to which a user is belonging to.
- To display the current user’s security processes.
- It also helps in finding out the Linux user’s group and effective group id (GID).
Syntax of id command
Syntax of id command is given below:
id [options] [user]
id [username] id [options] id [options] [username]
Note: When we use the id command without mentioning any option along with it, it will then print information of every user-specified.
How does the id command work in Linux?
Below are the options that we can use along with the id command in Linux in order to get the required details related to the user.
|-a||To ignore the compatibility with other versions in our system.|
|-Z, –context||To display the security texts of the processes.|
|-g, –group||To display the effective group ID|
|-G, –groups||To display all group IDs.|
|-n, –name||To display a name instead of a number, for -ugG|
|-r, –real||To display the real ID instead of the effective ID, with -ugG|
|-u, –user||To display only the effective user ID|
|-z, –zero||To eliminate entries with NUL characters, not whitespace. not permitted in the default format|
|–help||To print this help and exit|
|–version||To display the output version information and exit|
Examples of id command in Linux
Below are the examples listed for id command along with their options.
1. Option id
when we type only id command in Linux, then it provides the currently logged in user details, i.e., the user id and the group id and list of groups the user is present.
2. Option username
When we use the id command with any user name in Linux, it provides the user-specified details.
3. Option –u
To display only the user id of a user, we can use the id command along with option u.
id -u username
id -u master
4. Option –g
To display only the group id of the user, we can use the id command along with option g
id -g username
id -g master
5. Option –G
To display all the group’s ids in which the user is present, we can use the id command along with option G.
id -G username
id -G himanshu
6. Option –n
To display the user name and the names of all the groups he is present, we can use the id command along with option n and either of the options u/G/g.
id –nu username/id –ng username/id –nG username
id -nG master
Note: these commands give names of users or groups instead of ids.
7. Option –r
To display the real id’s of the user. This option can be used along with the options u/g/G.
id –ru username/id –rg username/id –rG username
id -r -G master
8. Option –Z
To display the user’s security context, we can use the id command along with option –Z.
id -Z username
id -Z master
Note: it works only if SELinux is enabled else;, it gives the error message.
9. Option –z
when the id command is used with this option, then it delimits the output character with null character instead of white space.
id -z username
id -z user
10. Option –help
to display the list of options available for id command along with their syntax, we can use this option –help.
11. Option –version
To display the version and other information
12. Option -un
This option will allow us to print the name instead of the number. We can combine this option with either -u or -g or -G.
13. Option -a
This option in the id command helps print the username and UID of the groups to which a user belongs.
The id command is very simple to understand and easy to use in Linux. However, the options related to the id command is very limited, and most of them are explained in the above examples.
The id command is basically used to know the basic information about any user logged on the server. When we specify the user name, it gives details of the specified user; otherwise, it provides details of the currently logged-in user. an id is a command-line-utility tool in Linux which is used to find out user and group names and real id’s of the current user or any other user in the server. It also gives us the list of groups the user is present and displays the current user’s security context when used with different options available for the command. This is mainly used for user management in a server.
This is a guide to Linux id. Here we discuss How does id command work in Linux, along with the Advantages and Examples. You may also have a look at the following articles to learn more –