The id command is a basic Linux command used to confirm the identity of a specified Linux user. It is also used to find user and group names, along with the UID and GID of any user in Linux. By default, the id command is available in all the Linux operating systems.
In this post, we will show you how to use the id command in Linux.
Prerequisites
- A fresh Ubuntu/CentOS server on the Atlantic.Net Cloud Platform
- A root password configured on your server
Create Atlantic.Net Cloud Server
First, log in to your Atlantic.Net Cloud Server. Create a new server, choosing Ubuntu/CentOS as the operating system with at least 2GB RAM. Connect to your Cloud Server via SSH and log in using the credentials highlighted at the top of the page.
Once you are logged in to your Ubuntu/CentOS server, run the following command to update your base system with the latest available packages.
apt-get update -y
Or
yum update -y
Basic Syntax
The basic syntax to use the id command is shown below:
id [OPTIONS] [USERNAME]
You can print all options with the following command:
id --help
You should see the following output:
Usage: id [OPTION]... [USERNAME] Print user and group information for the specified USERNAME, or (when USERNAME omitted) for the current user. -a ignore, for compatibility with other versions -Z, --context print only the security context of the current user -g, --group print only the effective group ID -G, --groups print all group IDs -n, --name print a name instead of a number, for -ugG -r, --real print the real ID instead of the effective ID, with -ugG -u, --user print only the effective user ID --help display this help and exit --version output version information and exit
How to Use id Command
Running the id command without any option will print the information about the current login user:
id
You should see the following output:
uid=1000(username) gid=1000(username) groups=1000(username),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),108(lpadmin),124(sambashare),125(vboxusers)
To print only the UID of a specific user, run the following command:
id -u username
Output:
1000
To print only the GID of a specific user, run the following command:
id -g username
Output:
1000
To print the UID and GID of a specific user, run the following command:
id username
Output:
uid=1000(username) gid=1000(username) groups=1000(username),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),108(lpadmin),124(sambashare),125(vboxusers)
To print the IDs of all other groups the user belongs to, run the following command:
id -G username
Output:
1000 4 24 27 30 46 108 124 125
To print a name instead of the ID, run the following command:
id -nG username
Output:
username adm cdrom sudo dip plugdev lpadmin sambashare vboxusers
To display real id instead of effective id, use the -r option:
id -r -u username
Output:
1000
Or
id -r -g username
Output:
1000
Or
id -r -G username
Output:
1000 4 24 27 30 46 108 124 125
Conclusion
In the above guide, you learned how to use the id command to find user and group id in Linux. This command is useful when your application needs UID or GID to be run; give it a try on your Atlantic.Net VPS.