id – Print Real and Valid User and Group Information

The id command in Linux is used to print the real and valid user and group information. It is a useful command for checking the user and group IDs of a particular user or group. This command is mostly used by system administrators to check user and group information.

Overview

The basic syntax of the id command is as follows:

id [options] [username]

When the id command is executed without any options or arguments, it displays the current user’s user ID (UID) and group ID (GID). If you specify a username as an argument, it will display the UID and GID of that user. Here are some examples:

$ id
uid=1000(john) gid=1000(john) groups=1000(john),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),116(lpadmin),126(sambashare)

$ id root
uid=0(root) gid=0(root) groups=0(root)

In the above examples, the first command displays the UID and GID of the current user (john) along with the groups that the user belongs to. The second command displays the UID and GID of the root user along with the groups that the user belongs to.

Options

The id command has several options that can be used to customize the output. Here is a table of available options:

Option Description
-g, –group Display only the group ID
-G, –groups Display all group IDs
-n, –name Display the name of the user or group
-r, –real Display the real ID instead of the effective ID
-u, –user Display only the user ID

Troubleshooting Tips

If you encounter issues with the id command, here are some troubleshooting tips:

  • If the command returns an error message indicating that the user or group does not exist, double-check the spelling of the username or group name.
  • If the command does not display any output, it is possible that the user or group has no ID associated with it.

Notes

  • The id command is useful for checking the UID and GID of a user or group, which is necessary for granting permissions to files and directories.
  • The id command can also be used in shell scripts to retrieve user and group information.