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:

id [OPTIONS] [USERNAME]

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.

id
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.

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

id -u
1000

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
1000

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
linuxid

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
unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023

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
linuxidadmsudodocker

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

Conclusion

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

Leave a Reply

Your email address will not be published. Required fields are marked *