Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> Linux技術

Linux 學習筆記:使用者與群組管理命令詳解

使用者管理

Linux 使用者管理常用命令包含 useradd、userdel、usermod、passwd、chsh、chfn、finger、id、chage。

新增使用者

useradd [options] USERNAME
useradd -u UID -g GID -G 群組1,群組2 -c 註解 -d /home/user -s /bin/bash user
useradd -M user
useradd -r serviceuser

-u 指定 UID,-g 指定基本群組,-G 指定附加群組,-d 指定家目錄,-s 指定 shell,-M 不建立家目錄,-r 建立系統使用者。

刪除與修改

userdel USERNAME
userdel -r USERNAME
usermod -u UID -g GID -G 群組 -a -G 新群組 -c 註解 -d 新家目錄 -m -s 新shell -l 新登入名 -L -U -e 日期 -f 天數 USERNAME

userdel 預設不刪家目錄,加 -r 才會一起刪除。usermod 可修改 UID、GID、附加群組、家目錄、shell、登入名、鎖定與過期設定。

密碼與資訊

passwd USERNAME
passwd --stdin USERNAME
passwd -l USERNAME
passwd -u USERNAME
passwd -d USERNAME
id USERNAME
finger USERNAME
chsh
chfn
chage -d -E -I -m -M -W USERNAME

passwd 可設定或鎖定密碼;id 查看 UID、GID 與群組;finger 查看帳號資訊;chage 管理密碼過期與非活動期。

群組管理

groupadd -g GID -r 群組名
groupmod -g GID -n 新群組名 群組名
groupdel 群組名
gpasswd 群組名
newgrp 群組名

groupadd 建立群組,groupmod 修改群組,groupdel 刪除群組,gpasswd 設定群組密碼,newgrp 可切換目前群組。

相關檔案與環境變數

/etc/login.defs 影響帳號建立預設值,/etc/shells 列出可用 shell。常用環境變數包含 PATH、HISTSIZE、SHELL。

Copyright © Linux教程網 All Rights Reserved