萬盛學電腦網

您现在的位置: 萬盛學電腦網 >> 作業系統 >  >> Linux 教學

Linux 帳號管理指令與關鍵配置檔完整介紹

一、帳號管理指令

1. 新增使用者

useradd sunday

常用選項:

  • -u 720 — 指定 UID
  • -g 100 — 指定初始群組
  • -M — 不建立家目錄
  • -d /path/to/dir — 指定家目錄路徑
  • -s /bin/bash — 指定預設登入 shell

完整範例:useradd -u 720 -g 100 -M -s /bin/bash sunday

2. 設定密碼

passwd sunday

3. 鎖定與解鎖帳號

  • usermod -L sunday — 鎖定,阻止登入
  • usermod -U sunday — 解鎖,恢復登入權限

4. 設定帳號過期時間

usermod -e 2008-08-08 sunday

5. 群組管理

  • groupadd debian — 新增群組
  • useradd -g debian sunday — 新增使用者指定群組
  • usermod -g debian sunday — 修改使用者初始群組
  • groupdel debian — 刪除群組

二、關鍵帳號配置檔

/etc/passwd

儲存使用者基本資訊,格式:

username:password:UID:GID:comment:home directory:shell
  • username — 使用者名稱
  • password — 密碼欄位(現代系統通常為 x,加密密碼存於 /etc/shadow)
  • UID — 使用者唯一識別碼
  • GID — 所屬群組識別碼
  • comment — 備註
  • home directory — 家目錄路徑
  • shell — 登入後執行的 shell

/etc/shadow

儲存加密密碼與密碼策略,格式:

username:encrypted_password:last_changed:min:max:warn:inactive:expire:reserved
  • encrypted_password — 加密口令,* 表示無法登入
  • last_changed — 上次改密碼日期(自 1970-01-01 起天數)
  • min — 兩次改密碼最小間隔天數
  • max — 密碼有效期限天數
  • warn — 過期前警告天數
  • inactive — 過期後帳號停用天數
  • expire — 帳號停用絕對日期(自 1970-01-01 起天數)
  • reserved — 保留欄位

範例:drobbins:$1$1234567890123456789012345678901:11664:0:-1:-1:-1:-1:0

/etc/group

儲存群組資訊,格式:

groupname:x:GID:usernames
  • groupname — 群組名稱
  • x — 群組密碼存於 /etc/shadow
  • GID — 群組識別碼
  • usernames — 群組成員列表,逗號分隔

範例:root:x:0:root,sunday,onlyisi

copyright © 萬盛學電腦網 all rights reserved