In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail how to check the user's group on Linux. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
Adding users to an existing group is one of the general activities of Linux administrators. This is the daily activity of some administrators working in a larger environment.
I even do this every day in my environment because of business needs. It is one of the important commands to help you identify existing groups in your environment.
In addition, these commands can help you identify the group to which the user belongs. All users are listed in / etc/passwd and groups are listed in / etc/group.
No matter what command we use, we will get the information from these files. In addition, each command has its own unique function to help users get the information they need individually.
What is / etc/passwd?
/ etc/passwd is a text file that contains each user information necessary to log in to the Linux system. It maintains useful user information, such as user name, password, user ID, group ID, user ID information, home directory, and shell. Each line of the passwd contains the details of the user, with a total of seven fields as described above.
$grep "daygeek" / etc/passwddaygeek:x:1000:1000:daygeek,:/home/daygeek:/bin/bash what is / etc/group?
/ etc/group is a text file that defines the group to which the user belongs. We can add multiple users to a single group. It allows users to access other user files and folders because Linux permissions are divided into three categories: users, groups, and others. It maintains useful information about groups, such as group names, group passwords, group ID (GID), and member lists. Each is on a separate line. Each line of the group file contains the details of each group, and there are four fields as described above.
This can be done by using the following methods.
Groups: displays all members of a group.
Id: prints user and group information for the specified user name.
Lid: the user that displays the user's group or group.
Getent: get the entry from the Name Service Switch library.
Grep: on behalf of
Global regular expression printing global regular expression print
Which can print matching patterns.
What is the groups command?
The groups command prints the name of the primary group and any supplementary groups for each given user name.
$groups daygeekdaygeek: daygeek adm cdrom sudo dip plugdev lpadmin sambashare
If you want to check the list of groups associated with the current user. Just run the groups command without any user name.
$groupsdaygeek adm cdrom sudo dip plugdev lpadmin sambashare what is the id command?
Id stands for "identity identity". It prints real and valid user and group ID. Prints user and group information for the specified user or the current user.
$id daygeekuid=1000 (daygeek) gid=1000 (daygeek) groups=1000 (daygeek), 4 (adm), 24 (cdrom), 27 (sudo), 30 (dip), 46 (plugdev), 118 (lpadmin), 128 (sambashare)
If you want to check the list of groups associated with the current user. Run only the id command without any user name.
Iduid=1000 (daygeek) gid=1000 (daygeek) groups=1000 (daygeek), 4 (adm), 24 (cdrom), 27 (sudo), 30 (dip), 46 (plugdev), 118 (lpadmin), 128 (sambashare) what is the lid command?
It displays the user's group or group of users. Displays information about the group or the users contained in the group name that contains the user name. This command requires administrator privileges.
$sudo lid daygeek adm (gid=4) cdrom (gid=24) sudo (gid=27) dip (gid=30) plugdev (gid=46) lpadmin (gid=108) daygeek (gid=1000) sambashare (gid=124) what is the getent command?
The getent command displays entries in databases supported by the Name Service Switch library, which are configured in / etc/nsswitch.conf.
$getent group | grep daygeekadm:x:4:syslog,daygeekcdrom:x:24:daygeeksudo:x:27:daygeekdip:x:30:daygeekplugdev:x:46:daygeeklpadmin:x:118:daygeekdaygeek:x:1000:sambashare:x:128:daygeek
If you only want to print the associated group name, use awk in the above command.
$getent group | grep daygeek | awk-F:'{print $1} 'admcdromsudodipplugdevlpadmindaygeeksambashare
Run the following command to print only the home group information.
$getent group daygeekdaygeek:x:1000: what is the grep command?
Grep stands for "global regular expression print global regular expression print", which prints the pattern that the file matches.
$grep "daygeek" / etc/groupadm:x:4:syslog,daygeekcdrom:x:24:daygeeksudo:x:27:daygeekdip:x:30:daygeekplugdev:x:46:daygeeklpadmin:x:118:daygeekdaygeek:x:1000:sambashare:x:128:daygeek
If you only want to print the associated group name, use awk in the above command.
$grep "daygeek" / etc/group | awk-F:'{print $1} 'admcdromsudodipplugdevlpadmindaygeeksambashare article on "how to check the user's group on Linux" ends here. I hope the above content can be helpful to you so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.