The Linux system consists of multiple users and groups; there might be a large number of users in your system that can be easily managed by adding them to a specific group.
After adding them, you can easily assign different permissions and policies to that specific group of users and remove them when they are not required.
A good example is sudo. If you are not part of the sudo group, you will not be able to perform any system level changes similar to that.
You might be part of many other groups that you can list using the groups command.
|Root or Sudo Privileges||No|
|Host System and Architecture||Ubuntu 22.10 (x64)|
|OS Compatibility||Ubuntu, Manjaro, Fedora, etc.|
Syntax of the Groups Command
groups” command takes one argument asking for a username, as shown.
$ groups [USERNAME]
Although you can specify multiple usernames by using the space as a separator.
Listing All Groups to Which a Specified User Belongs
Specify the “
username” with the groups command to list all the groups to which the specified user belongs.
$ groups linuxtldr
If you do not specify the “
username“, the groups command will show the result for the currently logged-in user.
Display the Current User’s UID, GID, and Groups to Which They Belong
The id command is used to display information about the current user’s ID (UID), group ID (GID), and groups to which they belong.
It is followed by the type with an “
=” sign, then the user or group ID, and the username.
Getting a Username Without a User ID
-n” and “
-G” flags can be used with the “
id” command to display only the name instead of a number.
$ id -nG
Listing All Groups in Your System
$ cat /etc/group
Alternatively, you can use the getent command to get the same output as above.
$ getent group
That was the end of the article.
If you have any thoughts, feel free to exchange them in the comment section.