1, using the / etc / passwd file.
cat /etc/passwd
/ Etc / passwd is a text file that contains information about each user's login Linux systems are necessary.
/ Etc / passwd file detailed information for each user to write a single line, which includes seven fields, each field between colon: separate:
Such as:
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
operator:x:11:0:operator:/root:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
systemd-bus-proxy:x:999:997:systemd Bus Proxy:/:/sbin/nologin
systemd-network:x:998:996:systemd Network Management:/:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
tcpdump:x:72:72::/:/sbin/nologin
admin:x:500:500::/home/admin:/bin/bash
Details of seven fields as follows:
Username (magesh): has created user name, character length of 1-12 characters.
Password (x): represents the encrypted password stored in `/ etc / shadow file.
User ID (506): represents the user's ID number, each user must have a unique ID. UID number 0 is reserved for the root user, UID number from 1 to 99 are reserved for system users, UID numbers 100-999 are reserved for system accounts and groups.
Group ID (507): on behalf of the group ID number, each group must have a unique GID, stored in / etc / group file.
User information (2g Admin - Magesh M): Representative description field can be used to describe the user information (LCTT Annotation: suspected error description herein).
Home directory (/ home / mageshm): represents the user's home directory.
** Shell (/ bin / bash) : Representative shell type used by the user.
Use awk or cut command to print out only the user name list of all users of the Linux system.
Note: python has a pwd module, which provides a Unix password database (/ etc / passwd file) interface, the database contains the local machine user account information.
usage:
import pwd
struct_passwd = pwd.getpwnam(username)
for i in struct_passwd :
print i
2、getent passwd
What is displayed with 1.
3、compgen -u
Show only the user name.