How to view all users in linux
How to view all users in Linux: 1. Use cat and other file operation commands to read the contents of the "/etc/passwd" file and print the user list created on the Linux system. 2. Use the getent command to view the syntax "getent passwd" to display user details similar to the "/etc/passwd" file. 3. Use the compgen command with the syntax "compgen -u".
#The operating environment of this tutorial: linux7.3 system, Dell G3 computer.
As we all know, user information in the Linux system is stored in the /etc/passwd file.
This is a text file containing basic information for each user. When we create a user in the system, the details of the new user are added to this file.
/etc/passwd The file records the basic information of each user as one line in the file, and one line contains 7 fields.
/etc/passwd A line in the file represents an individual user. This file divides the user's information into 3 parts.
* 第 1 部分:`root` 用户信息 * 第 2 部分:系统定义的账号信息 * 第 3 部分:真实用户的账户信息
The first part is the root account, this represents the administrator account and has complete power over every aspect of the system.
The second part is the system-defined groups and accounts that are required to correctly install and update system software.
The third part is at the end and represents a real user using the system.
When creating a new user, the following 4 files will be modified.
* `/etc/passwd`: 用户账户的详细信息在此文件中更新。 * `/etc/shadow`: 用户账户密码在此文件中更新。 * `/etc/group`: 新用户群组的详细信息在此文件中更新。 * `/etc/gshadow`: 新用户群组密码在此文件中更新。
Method 1: Use /etc/passwd
file
Use any of the file manipulation commands like cat, more, less etc. to print the list of users created on the Linux system.
/etc/passwd is a text file that contains the information for each user necessary to log in to the Linux system. It saves user's useful information 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 containing seven fields, each separated by a colon ::
# cat /etc/passwd root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nologin adm:x:3:4:adm:/var/adm:/sbin/nologin lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin sync:x:5:0:sync:/sbin:/bin/sync shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown halt:x:7:0:halt:/sbin:/sbin/halt mail:x:8:12:mail:/var/spool/mail:/sbin/nologin ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin postfix:x:89:89::/var/spool/postfix:/sbin/nologin sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin tcpdump:x:72:72::/:/sbin/nologin 2gadmin:x:500:10::/home/viadmin:/bin/bash apache:x:48:48:Apache:/var/www:/sbin/nologin zabbix:x:498:499:Zabbix Monitoring System:/var/lib/zabbix:/sbin/nologin mysql:x:497:502::/home/mysql:/bin/bash zend:x:502:503::/u01/zend/zend/gui/lighttpd:/sbin/nologin rpc:x:32:32:Rpcbind Daemon:/var/cache/rpcbind:/sbin/nologin 2daygeek:x:503:504::/home/2daygeek:/bin/bash named:x:25:25:Named:/var/named:/sbin/nologin mageshm:x:506:507:2g Admin - Magesh M:/home/mageshm:/bin/bash
The details of the 7 fields are as follows.
- 用户名 (magesh): 已创建用户的用户名,字符长度 1 个到 12 个字符。
- 密码(x):代表加密密码保存在 `/etc/shadow 文件中。
- **用户 ID(506):代表用户的 ID 号,每个用户都要有一个唯一的 ID 。UID 号为 0 的是为 root 用户保留的,UID 号 1 到 99 是为系统用户保留的,UID 号 100-999 是为系统账户和群组保留的。
- **群组 ID (507):代表群组的 ID 号,每个群组都要有一个唯一的 GID ,保存在 /etc/group文件中。
- **用户信息(2g Admin - Magesh M):代表描述字段,可以用来描述用户的信息(LCTT 译注:此处原文疑有误)。
- **家目录(/home/mageshm):代表用户的家目录。
- **Shell(/bin/bash):代表用户使用的 shell 类型。
你可以使用 awk 或 cut 命令仅打印出 Linux 系统中所有用户的用户名列表。显示的结果是相同的。
# awk -F':' '{ print $1}' /etc/passwd or # cut -d: -f1 /etc/passwd root bin daemon adm lp sync shutdown halt mail ftp postfix sshd tcpdump 2gadmin apache zabbix mysql zend rpc 2daygeek named mageshm
方法 2 :使用 getent
命令
getent 命令显示 Name Service Switch 库支持的数据库中的条目。这些库的配置文件为 /etc/nsswitch.conf。
getent 命令显示类似于 /etc/passwd 文件的用户详细信息,它将每个用户详细信息显示为包含七个字段的单行。
# getent passwd root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nologin adm:x:3:4:adm:/var/adm:/sbin/nologin lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin sync:x:5:0:sync:/sbin:/bin/sync shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown halt:x:7:0:halt:/sbin:/sbin/halt mail:x:8:12:mail:/var/spool/mail:/sbin/nologin ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin postfix:x:89:89::/var/spool/postfix:/sbin/nologin sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin tcpdump:x:72:72::/:/sbin/nologin 2gadmin:x:500:10::/home/viadmin:/bin/bash apache:x:48:48:Apache:/var/www:/sbin/nologin zabbix:x:498:499:Zabbix Monitoring System:/var/lib/zabbix:/sbin/nologin mysql:x:497:502::/home/mysql:/bin/bash zend:x:502:503::/u01/zend/zend/gui/lighttpd:/sbin/nologin rpc:x:32:32:Rpcbind Daemon:/var/cache/rpcbind:/sbin/nologin 2daygeek:x:503:504::/home/2daygeek:/bin/bash named:x:25:25:Named:/var/named:/sbin/nologin mageshm:x:506:507:2g Admin - Magesh M:/home/mageshm:/bin/bash
7 个字段的详细信息如上所述。(LCTT 译注:此处内容重复,删节)
你同样可以使用 awk 或 cut 命令仅打印出 Linux 系统中所有用户的用户名列表。显示的结果是相同的。
方法 3 :使用 compgen
命令
compgen 是 bash 的内置命令,它将显示所有可用的命令,别名和函数。
# compgen -u root bin daemon adm lp sync shutdown halt mail ftp postfix sshd tcpdump 2gadmin apache zabbix mysql zend rpc 2daygeek named mageshm
相关推荐:《Linux视频教程》
The above is the detailed content of How to view all users in linux. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

DeepSeek is a powerful intelligent search and analysis tool that provides two access methods: web version and official website. The web version is convenient and efficient, and can be used without installation; the official website provides comprehensive product information, download resources and support services. Whether individuals or corporate users, they can easily obtain and analyze massive data through DeepSeek to improve work efficiency, assist decision-making and promote innovation.

There are many ways to install DeepSeek, including: compile from source (for experienced developers) using precompiled packages (for Windows users) using Docker containers (for most convenient, no need to worry about compatibility) No matter which method you choose, Please read the official documents carefully and prepare them fully to avoid unnecessary trouble.

Ouyi OKX, the world's leading digital asset exchange, has now launched an official installation package to provide a safe and convenient trading experience. The OKX installation package of Ouyi does not need to be accessed through a browser. It can directly install independent applications on the device, creating a stable and efficient trading platform for users. The installation process is simple and easy to understand. Users only need to download the latest version of the installation package and follow the prompts to complete the installation step by step.

BITGet is a cryptocurrency exchange that provides a variety of trading services including spot trading, contract trading and derivatives. Founded in 2018, the exchange is headquartered in Singapore and is committed to providing users with a safe and reliable trading platform. BITGet offers a variety of trading pairs, including BTC/USDT, ETH/USDT and XRP/USDT. Additionally, the exchange has a reputation for security and liquidity and offers a variety of features such as premium order types, leveraged trading and 24/7 customer support.

Gate.io is a popular cryptocurrency exchange that users can use by downloading its installation package and installing it on their devices. The steps to obtain the installation package are as follows: Visit the official website of Gate.io, click "Download", select the corresponding operating system (Windows, Mac or Linux), and download the installation package to your computer. It is recommended to temporarily disable antivirus software or firewall during installation to ensure smooth installation. After completion, the user needs to create a Gate.io account to start using it.

Ouyi, also known as OKX, is a world-leading cryptocurrency trading platform. The article provides a download portal for Ouyi's official installation package, which facilitates users to install Ouyi client on different devices. This installation package supports Windows, Mac, Android and iOS systems. Users can choose the corresponding version to download according to their device type. After the installation is completed, users can register or log in to the Ouyi account, start trading cryptocurrencies and enjoy other services provided by the platform.

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

Causes and solutions for errors when using PECL to install extensions in Docker environment When using Docker environment, we often encounter some headaches...
