Linux Id Command Tutorial

50

It is difficult for a new Linux user to monitor users or groups’ names with their Ids/Gids. In Linux distributions, an id is a command-line tool that is used to display the real and effective user’s Id and group’s Ids.

The real id is the one that owns the system; it points towards you if you’re an account owner. The effective id is similar to Real id but with some limitations.

You don’t need to download or install the id command utility, as it is a built-in tool in Linux-like systems.

Syntax of Id Command

id [Options]…[User Name]

Id Command

To display your own identity, type id in the terminal. It will display your id, primary group id, and supplementary groups ids if they exist.

Id Commands with Options

Here are some options to show the working of the id command utility.

Let’s get started:

1. To get a specific user’s id, use the “-u” option.

Linux Id Command Tutorial 1617239322 674 Linux Id Command Tutorial

2. “-g” represents groups, so if you want to display a specific GID, use this option in the terminal:

Linux Id Command Tutorial 1617239323 557 Linux Id Command Tutorial

3. To display all groups ids a user belongs to, the “-G” option will be used:

Linux Id Command Tutorial 1617239323 767 Linux Id Command Tutorial

4. The “help” option is used to print help documents in the terminal for guidance and then exit.

Linux Id Command Tutorial 1617239324 310 Linux Id Command Tutorial

Few other options are listed below that can be used when required:

Z:  To display security contest

-r:  To display real ids

-z:  To delimit entries through Null characters

-n:  To display name instead of the number

Now, let’s check how to print the name instead of the number using the -n option.

For example, if I want to print names of all groups the user belongs to instead of their ids, I will use the following command:

Linux Id Command Tutorial 1617239324 549 Linux Id Command Tutorial

Here you can see, it prints names of all groups.

Similarly, you can use “-ng” for the real group name and “-nu” for the user’s name.

You can use the “-r” command with -u, -g, and -G options to display real id instead of effective id on the terminal.

For example, execute the following command to get real ids of the group, type:

Linux Id Command Tutorial 1617239325 912 Linux Id Command Tutorial

As you can see, we can get real ids with and without the username command.

We will get the same results.

Let’s see another example:

Linux Id Command Tutorial 1617239326 832 Linux Id Command Tutorial

And you can also get specific user’s details:

Linux Id Command Tutorial 1617239326 559 Linux Id Command Tutorial

Conclusion

We have learned from this tutorial how to use the “Id” command for real and effective IDs. The “Id” command is used to print the user’s identity, specific group id, and all groups ids the user belongs to. We have also checked multiple options of the Id command and their functionalities.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More