← 返回命令列表

Linux command

usermod 命令

安全

权限或系统影响较大,执行前请核对目标。

常用示例

Example

sudo usermod -l new_username username

Example

sudo usermod -u 1001 username

Example

sudo usermod -s /bin/zsh username

Add

sudo usermod -aG group1,group2 username

Set

sudo usermod -G group1,group2 username

Example

sudo usermod -m -d /new/home username

Lock

sudo usermod -L username

Unlock

sudo usermod -U username

说明

usermod modifies system account files to change user account attributes. It can update username, user ID, groups, home directory, shell, and account status.

参数

-a, --append
Append to supplementary groups (use with -G)
-c, --comment COMMENT
Change the comment field (GECOS)
-d, --home HOME_DIR
Set new home directory
-e, --expiredate DATE
Set account expiration date (YYYY-MM-DD)
-f, --inactive DAYS
Days after password expires until account disabled
-g, --gid GROUP
Change primary group
-G, --groups GROUP1,GROUP2
Set supplementary groups (replaces existing)
-l, --login NEW_LOGIN
Change username
-L, --lock
Lock the user account
-m, --move-home
Move home directory contents to new location
-o, --non-unique
Allow non-unique UID when used with -u
-p, --password PASSWORD
Set encrypted password (as returned by crypt(3))
-s, --shell SHELL
Change login shell
-u, --uid UID
Change user ID
-U, --unlock
Unlock the user account
-Z, --selinux-user SEUSER
Set SELinux user mapping

FAQ

What is the usermod command used for?

usermod modifies system account files to change user account attributes. It can update username, user ID, groups, home directory, shell, and account status.

How do I run a basic usermod example?

Run `sudo usermod -l new_username username` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -a, --append do in usermod?

Append to supplementary groups (use with -G)