Learn about Command id in Linux

Command id It is a command-line utility that prints user and group IDs.

Using the id command

The syntax of the id command is as follows:


If the input options username If deleted, the id command displays information about the currently registered user.

When connected without any options, the ID prints the user ID (uid), Primary group identifier (gid(And the true ID of the additional group)groups) Belongs to the user. User ID, Group ID, and Additional Group ID are printed only if they differ from the original.

uid=1000(linuxid) gid=1000(linuxid) groups=1000(linuxid),4(adm),27(sudo),998(docker)

If SELinux is enabled, the ID will also print the user’s security context (context):

uid=1000(linuxid) gid=1000(linuxid) groups=1000(linuxid) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023

To obtain information about other users, provide the username or user ID as arguments for the command id:

id diyan
uid=1001(diyan) gid=1001(diyan) groups=1001(diyan),998(docker)

If a user with the same name as the provided ID is present on the system, then name search takes precedence. When using UserID as an argument, start the identifier with an icon + To avoid interpreting the identifier as a name.

For example, if you have a user named 1010 And other users with IDs 1010, If you type an id 1010 The command will display information about the user by name 1010. To obtain information about users by identifier 1010, Type id +1010. This way, you can differentiate between names 1010 With Ridwan1010, siska 1010, etc.

Command Options ID

Command id It accepts several options that allow you to display only specific information. This is useful when using id scripts in a shell.

See also  Tutorial and use of Cron and Crontabs functions in Terminal

To print only effective user IDs, use the option -u (--user):

id -u

Selection -g (--group) The command will tell id to print only active group IDs:

id -g
1000 4 27 998

Use the options -G (--groups) To print the effective identifier for all user groups:

id -G

To print names instead of numbers, use the options -nAnd the --name. This option can only be used with -uAnd the -g And the -G.

id -un

Run the commands id With options -un It produces the same output by operating whoamiAnd the output id -Gn Equivalent to taking out the command groups .

Selection -r, (--real) In conjunction with -uAnd the -g And the -G To print the real values, not the hot values:

id -ur

To print only the process security context, which is usually the user’s security context, use the options -Z (--context):

id -Z

If SELinux is disabled, id It will print the following error message:

id: --context (-Z) works only on an SELinux-enabled kernel

Selection -z (--zeroNotification of requests id To specify output items with NUL letters instead of spaces:

id -znG

This can be useful when directing the output to a command that can parse new lines


The id command prints information about the specified user, or the currently logged in user if the username or id are not provided as arguments.


Source link

Originally posted 2020-11-17 19:06:15.

About wahyuway

Check Also

How to install and configure Anaconda on CentOS 7

How to install and configure Anaconda on CentOS 7

Anaconda is the most popular machine learning and data science tool used in large scale …

Leave a Reply