User groups in Linux

We have already spoken about Linux user groups on this site many times. This is the main and very convenient way to manage the permissions of users and processes in this operating system.

To view the list of users of a group in Linux is quite simple, for this there are several ways, and in this article we will consider all of them.

The content of the article

File /etc/group

All groups created in Linux are collected in the /etc/group file. The syntax of the group entry in this file is as follows:

group_name : x : id : user_list

group_name: the name that is used to manage the group and is displayed in the output of commands;
x: password (not stores real password)
id: a unique identifier of the group
user_list: all users who are members of the group, separated by a comma.

To view the list of members of the group (in this example group adm) we can use combination of cat and grep commands

$ cat /etc/group | grep adm
adm:x:4:syslog,gharutyunyan

Output of command shows that members of adm group are gharutyunyan and syslog users.

Command members

The next way to see the users of a group is the members command, in Ubuntu it comes by default. If it is not in your distribution, you can install it from the official repositories by sudo apt install members command.

 
$ sudo apt install members

$ members adm
syslog gharutyunyan

$ members --primary adm

$ members --secondary adm
syslog gharutyunyan

[adinserter block=”6″]

Command lid

The command lid can also display information about groups. But before you can use it, you need to install it. The command is included in the libuser package. In Ubuntu, the command looks like sudo apt install libuser.

To view the users of the group, it is enough, as in the previous case, to give the group name to the command.

$ sudo apt install libuser
$ sudo libuser-lid -g adm
 syslog(uid=103)
 gharutyunyan(uid=1000)

The -g option is required. If we do not pass it, the command will show the list of groups of the current user.

$ sudo libuser-lid
No user name specified, using root.
 root(gid=0)

If we do not pass the name of the group, the command will show the list of users of the main group of the current user.

$ sudo libuser-lid -g
No group name specified, using root.
 root(uid=0)

Conclusion

In this short article, we looked at how to manage a list of users in the Linux group. As you can see, there is nothing complicated. If you have any questions, ask in the comments!

Useful Articles

Source

losst.ru

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.