In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly shows you "how to see how many users linux has", the content is simple and easy to understand, organized clearly, I hope to help you solve doubts, let Xiaobian lead you to study and learn "how to see how many users linux has" this article bar.
Linux to see how many users: 1, open the terminal command window;2, by looking at the "/etc/passwd" file can see all the user information.
Operating environment: linux 5.9.8 system, Dell G3.
Three ways to see all users in linux
There are three ways to view user information on the system: using the/etc/passwd file, getent command, and compgen command.
View all users in Linux, in Terminal. The file/etc/passwd is not included.
Look at the third parameter:500 or more, is built behind the user. Others are users of the system. Or cat /etc/passwd| cut -f 1 -d :
As you all know, user information on Linux systems is stored in the/etc/passwd file.
This is a text file containing basic information about each user. When we create a user in the system, the details of the new user are added to this file.
The/etc/passwd file records basic information about each user as a single line in the file, which contains seven fields.
A line in the/etc/passwd file represents a single user. The file divides the user's information into three parts.
* Part 1:`root` user information
* Part 2: System-defined account information
* Part 3: Account information of real users
The first part is the root account, which represents the administrator account and has full authority over every aspect of the system.
The second part is the system-defined groups and accounts that are necessary to install and update the system software correctly.
The third section, at the end, represents a real user of the system.
The following four files are modified when a new user is created.
* `/etc/passwd`: Details of the user account are updated in this file.
* /etc/shadow: User account passwords are updated in this file.
* /etc/group: Details of new user groups are updated in this file.
* /etc/gshadow: New user group passwords are updated in this file.
Method 1: Use the/etc/passwd file
Use any file manipulation command like cat, more, less, etc. to print a list of users created on Linux.
/etc/passwd is a text file that contains the information for each user necessary to log on to the Linux system. It holds useful information about the user, such as username, password, user ID, group ID, user ID information, user's home directory, and Shell.
The/etc/passwd file writes each user's details as a single line with seven fields separated by colons:
# cat /etc/passwdroot:x:0:0:root:/root:/bin/bashbin:x:1:1:bin:/bin:/sbin/nologindaemon:x:2:2:daemon:/sbin:/sbin/nologinadm:x:3:4:adm:/var/adm:/sbin/nologinlp:x:4:7:lp:/var/spool/lpd:/sbin/nologinsync:x:5:0:sync:/sbin:/bin/syncshutdown:x:6:0:shutdown:/sbin:/sbin/shutdownhalt:x:7:0:halt:/sbin:/sbin/haltmail:x:8:12:mail:/var/spool/mail:/sbin/nologinftp:x:14:50:FTP User:/var/ftp:/sbin/nologinpostfix:x:89:89::/var/spool/postfix:/sbin/nologinsshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologintcpdump:x:72:72::/:/sbin/nologin2gadmin:x:500:10::/home/viadmin:/bin/bashapache:x:48:48:Apache:/var/www:/sbin/nologinzabbix:x:498:499:Zabbix Monitoring System:/var/lib/zabbix:/sbin/nologinmysql:x:497:502::/home/mysql:/bin/bashzend:x:502:503::/u01/zend/zend/gui/lighttpd:/sbin/nologinrpc:x:32:32:Rpcbind Daemon:/var/cache/rpcbind:/sbin/nologin2daygeek:x:503:504::/home/2daygeek:/bin/bashnamed:x:25:25:Named:/var/named:/sbin/nologinmageshm:x:506:507:2g Admin - Magesh M:/home/mageshm:/bin/bash
Details of the seven fields are as follows.
User name (magesh): The user name of the created user, 1 to 12 characters long.
Password (x): The encrypted password is stored in the `/etc/shadow file.
** User ID (506): Represents the ID number of the user, each user must have a unique ID. UID numbers 0 are reserved for root users, UID numbers 1 through 99 are reserved for system users, and UID numbers 100 through 999 are reserved for system accounts and groups.
** Group ID (507): The ID number representing the group. Each group must have a unique GID, which is stored in the/etc/group file.
** User information (2g Admin - Magesh M): Represents a description field that can be used to describe user information.
** Home directory (/home/mageshm): Represents the user's home directory.
**Shell (/bin/bash): Represents the type of shell the user uses.
You can use awk or cut to print out just a list of the usernames of all users on your Linux system. The results shown are the same.
# awk -F':' '{ print $1}' /etc/passwdor# cut -d: -f1 /etc/passwdrootbindaemonadmlpsyncshutdownhaltmailftppostfixsshdtcpdump2gadminapachezabbixmysqlzendrpc2daygeeknamedmageshm
Method 2: Use the getent command
The getent command displays entries from databases supported by the Name Service Switch library. The configuration file for these libraries is/etc/nsswitch.conf.
The getent command displays user details similar to the/etc/passwd file, displaying each user detail as a single line of seven fields.
# getent passwdroot:x:0:0:root:/root:/bin/bashbin:x:1:1:bin:/bin:/sbin/nologindaemon:x:2:2:daemon:/sbin:/sbin/nologinadm:x:3:4:adm:/var/adm:/sbin/nologinlp:x:4:7:lp:/var/spool/lpd:/sbin/nologinsync:x:5:0:sync:/sbin:/bin/syncshutdown:x:6:0:shutdown:/sbin:/sbin/shutdownhalt:x:7:0:halt:/sbin:/sbin/haltmail:x:8:12:mail:/var/spool/mail:/sbin/nologinftp:x:14:50:FTP User:/var/ftp:/sbin/nologinpostfix:x:89:89::/var/spool/postfix:/sbin/nologinsshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologintcpdump:x:72:72::/:/sbin/nologin2gadmin:x:500:10::/home/viadmin:/bin/bashapache:x:48:48:Apache:/var/www:/sbin/nologinzabbix:x:498:499:Zabbix Monitoring System:/var/lib/zabbix:/sbin/nologinmysql:x:497:502::/home/mysql:/bin/bashzend:x:502:503::/u01/zend/zend/gui/lighttpd:/sbin/nologinrpc:x:32:32:Rpcbind Daemon:/var/cache/rpcbind:/sbin/nologin2daygeek:x:503:504::/home/2daygeek:/bin/bashnamed:x:25:25:Named:/var/named:/sbin/nologinmageshm:x:506:507:2g Admin - Magesh M:/home/mageshm:/bin/bash
Details of the 7 fields are described above. (LCTT)
You can also use awk or cut to print out just a list of the usernames of all users on Linux. The results shown are the same.
Method 3: Using compgen
Compgen is bash's built-in command, which displays all available commands, aliases, and functions.
# compgen -urootbindaemonadmlpsyncshutdownhaltmailftppostfixsshdtcpdump2gadminapachezabbixmysqlzendrpc2daygeeknamedmageshm
That's all for linux how to see how many users there are. Thanks for reading! I believe that everyone has a certain understanding, hope to share the content to help everyone, if you still want to learn more knowledge, welcome to pay attention to the industry information channel!
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.