


linux的“etc”目录下存放着用户信息。etc目录用来存放系统主要的配置文件,例如用户的账号密码等文件;该目录下的passwd文件是系统用户配置文件,存储了系统中所有用户的基本信息,而shadow文件存储了系统中用户的密码信息。
本教程操作环境:linux5.9.8系统、Dell G3电脑。
linux的“etc”目录下存放着用户信息。
Linux etc是用来存放系统主要的配置文件,例如用户的账号密码文件、各种服务的起始文件等,一般来说这个目录下的各文件属性是可以让一般用户进行查阅的,但是只有root才有权利进行修改。
etc目录下存放用户信息的文件
1、/etc/passwd 文件
/etc/passwd 文件,是系统用户配置文件,存储了系统中所有用户的基本信息,并且所有用户都可以对此文件执行读操作。
我们借助 Vim 命令查看一下此文件,看看到底包含哪些内容,执行命令如下:
[root@localhost ~]# vi /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 ...省略部分输出...
可以看到,/etc/passwd 文件中的内容非常规律,每行记录对应一个用户。
读者可能会问,Linux 系统中默认怎么会有这么多的用户?这些用户中的绝大多数是系统或服务正常运行所必需的用户,这种用户通常称为系统用户或伪用户。系统用户无法用来登录系统,但也不能删除,因为一旦删除,依赖这些用户运行的服务或程序就不能正常执行,会导致系统问题。
不仅如此,每行用户信息都以 ":" 作为分隔符,划分为 7 个字段,每个字段所表示的含义如下:
用户名:密码:UID(用户ID):GID(组ID):描述性信息:主目录:默认Shell
2、/etc/shadow 文件
/etc/shadow 文件,用于存储 Linux 系统中用户的密码信息,又称为“影子文件”。
由于/etc/passwd文件允许所有用户读取,易导致用户密码泄露,因此 Linux 系统将用户的密码信息从 /etc/passwd 文件中分离出来,并单独放到了此文件中。
/etc/shadow 文件只有 root 用户拥有读权限,其他用户没有任何权限,这样就保证了用户密码的安全性。
注意,如果这个文件的权限发生了改变,则需要注意是否是恶意攻击。
介绍此文件之前,我们先打开看看,执行如下命令:
[root@localhost ~]#vim /etc/shadow root: $6$9w5Td6lg $bgpsy3olsq9WwWvS5Sst2W3ZiJpuCGDY.4w4MRk3ob/i85fl38RH15wzVoom ff9isV1 PzdcXmixzhnMVhMxbvO:15775:0:99999:7::: bin:*:15513:0:99999:7::: daemon:*:15513:0:99999:7::: …省略部分输出…
同 /etc/passwd 文件一样,文件中每行代表一个用户,同样使用 ":" 作为分隔符,不同之处在于,每行用户信息被划分为 9 个字段。每个字段的含义如下:
用户名:加密密码:最后一次修改时间:最小修改时间间隔:密码有效期:密码需要变更前的警告天数:密码过期后的宽限时间:账号失效时间:保留字段
3、/ect/group 文件
/ect/group 文件是用户组配置文件,即用户组的所有信息都存放在此文件中。
此文件是记录组 ID(GID)和组名相对应的文件。前面讲过,etc/passwd 文件中每行用户信息的第四个字段记录的是用户的初始组 ID,那么,此 GID 的组名到底是什么呢?就要从 /etc/group 文件中查找。
/etc/group 文件的内容可以通过 Vim 看到:
[root@localhost ~]#vim /etc/group root:x:0: bin:x:1:bin,daemon daemon:x:2:bin,daemon …省略部分输出… lamp:x:502:
可以看到,此文件中每一行各代表一个用户组。在前面章节中,我们曾创建 lamp 用户,系统默认生成一个 lamp 用户组,在此可以看到,此用户组的 GID 为 502,目前它仅作为 lamp 用户的初始组。
各用户组中,还是以 ":" 作为字段之间的分隔符,分为 4 个字段,每个字段对应的含义为:
组名:密码:GID:该用户组中的用户列表
4、/etc/gshadow 文件
/etc/gshadow 文件:存储组用户的密码信息
我们借助 Vim 命令查看一下此文件中的内容:
[root@localhost ~]#vim /etc/gshadow root::: bin:::bin, daemon daemon:::bin, daemon ...省略部分输出... lamp:!::
文件中,每行代表一个组用户的密码信息,各行信息用 ":" 作为分隔符分为 4 个字段,每个字段的含义如下:
组名:加密密码:组管理员:组附加用户列表
相关推荐:《Linux视频教程》
The above is the detailed content of Which directory in Linux stores user information?. For more information, please follow other related articles on the PHP Chinese website!

MaintenanceModeinLinuxisaspecialbootenvironmentforcriticalsystemmaintenancetasks.Itallowsadministratorstoperformtaskslikeresettingpasswords,repairingfilesystems,andrecoveringfrombootfailuresinaminimalenvironment.ToenterMaintenanceMode,interrupttheboo

The core components of Linux include kernel, file system, shell, user and kernel space, device drivers, and performance optimization and best practices. 1) The kernel is the core of the system, managing hardware, memory and processes. 2) The file system organizes data and supports multiple types such as ext4, Btrfs and XFS. 3) Shell is the command center for users to interact with the system and supports scripting. 4) Separate user space from kernel space to ensure system stability. 5) The device driver connects the hardware to the operating system. 6) Performance optimization includes tuning system configuration and following best practices.

The five basic components of the Linux system are: 1. Kernel, 2. System library, 3. System utilities, 4. Graphical user interface, 5. Applications. The kernel manages hardware resources, the system library provides precompiled functions, system utilities are used for system management, the GUI provides visual interaction, and applications use these components to implement functions.

Linux maintenance mode can be entered through the GRUB menu. The specific steps are: 1) Select the kernel in the GRUB menu and press 'e' to edit, 2) Add 'single' or '1' at the end of the 'linux' line, 3) Press Ctrl X to start. Maintenance mode provides a secure environment for tasks such as system repair, password reset and system upgrade.

The steps to enter Linux recovery mode are: 1. Restart the system and press the specific key to enter the GRUB menu; 2. Select the option with (recoverymode); 3. Select the operation in the recovery mode menu, such as fsck or root. Recovery mode allows you to start the system in single-user mode, perform file system checks and repairs, edit configuration files, and other operations to help solve system problems.

The core components of Linux include the kernel, file system, shell and common tools. 1. The kernel manages hardware resources and provides basic services. 2. The file system organizes and stores data. 3. Shell is the interface for users to interact with the system. 4. Common tools help complete daily tasks.

The basic structure of Linux includes the kernel, file system, and shell. 1) Kernel management hardware resources and use uname-r to view the version. 2) The EXT4 file system supports large files and logs and is created using mkfs.ext4. 3) Shell provides command line interaction such as Bash, and lists files using ls-l.

The key steps in Linux system management and maintenance include: 1) Master the basic knowledge, such as file system structure and user management; 2) Carry out system monitoring and resource management, use top, htop and other tools; 3) Use system logs to troubleshoot, use journalctl and other tools; 4) Write automated scripts and task scheduling, use cron tools; 5) implement security management and protection, configure firewalls through iptables; 6) Carry out performance optimization and best practices, adjust kernel parameters and develop good habits.


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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

SublimeText3 English version
Recommended: Win version, supports code prompts!

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.