目錄
What's in the /etc/passwd file?
Why does /etc/shadow exist?
Common tools that interact with these files
首頁 系統教程 Linux /etc /passWD和 /etc /shadow文件的目的是什麼?

/etc /passWD和 /etc /shadow文件的目的是什麼?

Jun 23, 2025 am 12:22 AM

/etc/passwd存儲用戶基本信息,/etc/shadow保存加密密碼及認證信息。 1. /etc/passwd包含用戶名、UID、GID、註釋、主目錄、shell等字段,用於存儲所有用戶可讀的賬戶信息;2. /etc/shadow保存加密密碼、密碼更改時間、有效期等敏感數據,僅root可讀以提高安全性;3. 兩者分離設計是為了避免將密碼暴露給所有用戶,從而增強系統安全;4. 管理員應使用useradd、passwd、chage等命令修改賬戶信息,而非直接編輯文件。

What is the purpose of the /etc/passwd and /etc/shadow files?

The /etc/passwd and /etc/shadow files are both essential components of user account management in Unix-like operating systems. They store critical information about users, but serve different purposes — mainly separating user metadata from sensitive authentication data.

What's in the /etc/passwd file?

This file contains basic user account information that needs to be readable by all users. Each line represents a user account and includes seven fields separated by colons:

 username:x:UID:GID:comment:home_directory:shell
  • username : The name used to log in.
  • x : Indicates that the password is stored in /etc/shadow .
  • UID : User ID number (0 for root, 1–999 system accounts, 1000 regular users).
  • GID : Primary group ID.
  • comment : Optional field for full name or contact info.
  • home_directory : Path to the user's home directory.
  • shell : The program launched on login (usually a shell like /bin/bash ).

You'll often see service accounts here with no login shell (eg, /usr/sbin/nologin ) and system accounts with low UIDs.

Why does /etc/shadow exist?

Storing passwords directly in /etc/passwd would be a security risk since that file must be world-readable. That's why /etc/shadow was introduced — it holds sensitive login information and is only readable by root.

Each line in /etc/shadow looks like this:

 username:$hash:since_last_change:min_age:max_age:warn_period:expire_date:disabled
  • $hash : Encrypted password (or * , ! , !! , etc., if locked or expired).
  • since_last_change : Days since Jan 1, 1970, that the password was last changed.
  • min_age : Minimum days before password can be changed.
  • max_age : Maximum days password is valid.
  • warn_period : Days before password expiry to warn user.
  • expire_date : Days since Jan 1, 1970, when account will expire.
  • disabled : Days after password expiry until account is locked.

This setup allows administrators to enforce password policies and manage account expiration securely.

Common tools that interact with these files

Several command-line utilities are designed to safely modify these files without editing them directly:

  • useradd , userdel , usermod – for managing user accounts.
  • groupadd , groupdel , groupmod – for managing groups.
  • passwd – to change a user's password.
  • chage – to adjust password expiry information.

These commands ensure proper syntax and permissions are maintained, reducing the chance of breaking user access or system integrity.

If you ever need to look at these files:

  • Use cat /etc/passwd (safe to view)
  • Use sudo cat /etc/shadow (requires elevated privileges)

Just remember, direct edits should be rare and always backed up.

基本上就這些。

以上是/etc /passWD和 /etc /shadow文件的目的是什麼?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

在RHEL,Rocky和Almalinux中安裝LXC(Linux容器) 在RHEL,Rocky和Almalinux中安裝LXC(Linux容器) Jul 05, 2025 am 09:25 AM

LXD被描述為下一代容器和虛擬機管理器,它為在容器內部或虛擬機中運行的Linux系統提供了沉浸式的。 它為有支持的Linux分佈數量提供圖像

如何在Linux中安裝R編程語言 如何在Linux中安裝R編程語言 Jun 23, 2025 am 09:51 AM

R是一種廣泛使用的編程語言和軟件環境,旨在在數據科學中開發統計和圖形計算工具。它與S編程語言和環境非常相似,R是替代方案

在Linux桌面中加快Firefox瀏覽器的7種方法 在Linux桌面中加快Firefox瀏覽器的7種方法 Jul 04, 2025 am 09:18 AM

Firefox瀏覽器是大多數現代Linux分佈(例如Ubuntu,Mint和Fedora)的默認瀏覽器。最初,它的性能可能令人印象深刻,但是隨著時間的流逝,您可能會注意到瀏覽器的快速和響應不佳

清晰的Linux發行版 - 針對性能和安全性進行了優化 清晰的Linux發行版 - 針對性能和安全性進行了優化 Jul 02, 2025 am 09:49 AM

Clear Linux OS是人們想要最小,安全和可靠的Linux分佈的理想操作系統 - Ahem System Admins。它針對英特爾體系結構進行了優化,這意味著在AMD SYS上運行Clear Linux OS

如何在Linux中隱藏文件和目錄 如何在Linux中隱藏文件和目錄 Jun 26, 2025 am 09:13 AM

您有時會與家人,朋友或同事共享Linux桌面?如果是這樣,您可能需要隱藏一些個人文件和文件夾。挑戰是弄清楚如何在Linux系統上隱藏這些文件。在本指南中,我們將瀏覽

如何使用OpenSSL創建自簽名的SSL證書? 如何使用OpenSSL創建自簽名的SSL證書? Jul 03, 2025 am 12:30 AM

創建自簽名SSL證書的關鍵步驟如下:1.生成私鑰,使用命令opensslgenrsa-outselfsigned.key2048生成一個2048位的RSA私鑰文件,可選參數-aes256實現密碼保護;2.創建證書請求(CSR),運行opensslreq-new-keyselfsigned.key-outselfsigned.csr並填寫相關信息,特別是“CommonName”字段;3.自簽名生成證書,通過opensslx509-req-days365-inselfsigned.csr-signk

如何提取.tar.gz或.zip文件? 如何提取.tar.gz或.zip文件? Jul 02, 2025 am 12:52 AM

在Windows上解壓.zip文件可右鍵選擇“全部提取”,而.tar.gz文件需借助7-Zip或WinRAR等工具;在macOS和Linux上,.zip文件可雙擊或使用unzip命令解壓,.tar.gz文件可用tar命令或直接雙擊解壓。具體步驟為:1.Windows處理.zip文件:右鍵→“全部提取”;2.Windows處理.tar.gz文件:安裝第三方工具→右鍵解壓;3.macOS/Linux處理.zip文件:雙擊或運行unzipfilename.zip;4.macOS/Linux處理.tar

linux系統中的理解 /etc /mtab文件參數 linux系統中的理解 /etc /mtab文件參數 Jun 23, 2025 am 09:47 AM

在本文中,我們將仔細研究Linux中的 /etc /mtab文件,並檢查其中包含的不同參數和設置。理解在linuxthe /etc /mtab文件中使用 /etc /mtab文件用於列出所有當前安裝的文件系統。一個

See all articles