useradd 命令詳解


useradd 能建立用戶帳戶,創建主目錄。

用戶帳戶建好後,再用 passwd 設定帳戶口令; 此外,還可用 userdel 刪除帳戶。

使用 useradd 命令建立的帳戶,實際位於 /etc/passwd 文件中。

另請參閱: adduser     mkdir     passwd     userdel

基本用法     詳細用法

useradd USER
 
useradd --system USER
			

基本語法

useradd [options] LOGIN
 
useradd -D
 
useradd -D [options]
			

Options 選項

參數 EN 解釋 中文翻譯 備注
-b, --base-dir BASE_DIR base directory for the home directory of the new account 新帳戶主目錄的基目錄
-c, --comment COMMENT GECOS field of the new account 新帳戶 GECOS 字段
-d, --home-dir HOME_DIR home directory of the new account 新帳戶主目錄
-D, --defaults print or change default useradd configuration 打印或更改默認 useradd 配置
-e, --expiredate EXPIRE_DATE expiration date of the new account 新帳戶過期日期
-f, --inactive INACTIVE password inactivity period of the new account 新帳戶口令不活躍期
-g, --gid GROUP name or ID of the primary group of the new account 新帳戶首要組名或 ID
-G, --groups GROUPS list of supplementary groups of the new account 新帳戶補充組列錶
-h, --help display this help message and exit 顯示幫助消息並退齣
-k, --skel SKEL_DIR use this alternative skeleton directory 使用此備用骨架目錄
-K, --key KEY=VALUE override /etc/login.defs defaults 覆蓋 /etc/login.defs 默認值
-l, --no-log-init do not add the user to the lastlog and faillog databases 不要將用戶添加到 lastlog 和 faillog 數據庫
-m, --create-home create the user's home directory 創建用戶主目錄
-M, --no-create-home do not create the user's home directory 不創建用戶主目錄
-N, --no-user-group do not create a group with the same name as the user 不要創建與用戶同名的組
-o, --non-unique allow to create users with duplicate (non-unique) UID 允許創建具有重復 (非唯一) UID 的用戶
-p, --password PASSWORD encrypted password of the new account 加密新帳戶口令
-r, --system create a system account 創建係統帳戶
-R, --root CHROOT_DIR directory to chroot into chroot 進入的目錄
-s, --shell SHELL login shell of the new account 新帳戶登錄 shell
-u, --uid UID user ID of the new account 新帳戶用戶 ID
-U, --user-group create a group with the same name as the user 創建與用戶同名的組
-Z, --selinux-user SEUSER use a specific SEUSER for the SELinux user mapping 使用特定 SEUSER 進行 SELinux 用戶映射
--extrausers Use the extra users database 使用額外用戶數據庫

基本用法

功能 命令 文字解釋 示例 示例解釋
添加 useradd USER 添加 USER 普通用戶
useradd --system USER 添加 USER 係統用戶 useradd -r digitser 添加 digitser 係統用戶
根目錄 useradd -d HOME_DIR -m USER

添加 USER 普通用戶

根目錄 HOME_DIR

useradd -d /home/ftp -m ftp

添加 ftpuser 普通用戶

根目錄為 /home/ftp

useradd --home-dir HOME_DIR --create-home USER

添加 USER 普通用戶

根目錄 HOME_DIR

useradd --home-dir /home/ftp --create-home ftp

添加 ftpuser 普通用戶

根目錄 /home/ftp

幫助 useradd -h 展示幫助信息
useradd --help

 

版權聲明: 本文為獨傢原創稿件,版權歸 樂數軟件 ,未經許可不得轉載。