Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The method of viewing user information in linux

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article is about how linux views user information. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

What is Linux system Linux is a free-to-use and free-spread UNIX-like operating system, is a POSIX-based multi-user, multi-task, multi-threaded and multi-CPU operating system, using Linux can run major Unix tools, applications and network protocols.

Linux to view user information: 1, use the "cat / etc/passwd" command to output the details of each user; 2, use the "getent passwd" command to display each user's details as a single line containing seven fields; 3, use the "compgen-u" command.

The operating environment of this tutorial: Red Hat Enterprise Linux 6.1 system, Dell G3 computer.

Method 1: use the / etc/passwd file

Use any of the file manipulation commands like cat, more, less, etc., to print a list of users created on the Linux system.

/ etc/passwd is a text file that contains information about each user necessary to log in to the Linux system. It holds useful information about the user, such as user name, password, user ID, group ID, user ID information, user's home directory and Shell.

The / etc/passwd file writes the details of each user on one line, containing seven fields, each separated by a colon:

# 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

The details of the seven fields are as follows

User name (magesh): the user name of the created user, with a length of 1 to 12 characters.

Password (x): means that the encrypted password is saved in the `/ etc/shadow file.

* * user ID: represents the ID number of the user, and 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-999 are reserved for system accounts and groups.

* * Group ID: represents the ID number of the group. Each group must have a unique GID, which is saved in the / etc/group file.

* * user information (2g Admin-Magesh M): represents the description field and can be used to describe the user's information. (LCTT translation note: the original text here is suspected to be incorrect).

* * Home directory (/ home/mageshm): represents the user's home directory.

* * Shell (/ bin/bash): represents the type of shell used by the user.

You can use the awk or cut command to print out only a list of the user names of all users in the Linux system. The results displayed are the same.

# awk-fanglu'{print $1}'/ etc/passwdor# cut-d:-F1 / etc/passwdrootbindaemonadmlpsyncshutdownhaltmailftppostfixsshdtcpdump2gadminapachezabbixmysqlzendrpc2daygeeknamedmageshm

Method 2: use the getent command

The getent command displays entries in 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, which displays each user details as a single line with 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

The details of the 7 fields are described above. (LCTT translation note: the content here is duplicated, abridged)

You can also use the awk or cut command to print out only a list of user names for all users on the Linux system. The results displayed are the same.

Method 3: use the compgen command

Compgen is a built-in command for bash that displays all available commands, aliases, and functions.

# compgen-urootbindaemonadmlpsyncshutdownhaltmailftppostfixsshdtcpdump2gadminapachezabbixmysqlzendrpc2daygeeknamedmageshm Thank you for reading! This is the end of this article on "linux's way to view user information". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can 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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report