LinuxCommandLibrary

usermod

Modify user account attributes

TLDR

TLDR

Change username

$ sudo usermod -l new_username username
copy
Change user ID
$ sudo usermod -u 1001 username
copy
Change user shell
$ sudo usermod -s /bin/zsh username
copy
Add user to supplementary groups
$ sudo usermod -aG group1,group2 username
copy
Remove user from groups
$ sudo usermod -rG group1,group2 username
copy
Change home directory and move contents
$ sudo usermod -m -d /new/home username
copy
Lock an account
$ sudo usermod -L username
copy
Unlock an account
$ sudo usermod -U username
copy

SYNOPSIS

usermod [options] LOGIN

DESCRIPTION

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

PARAMETERS

-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
-p, --password PASSWORD
Set encrypted password
-r, --remove
Remove user from specified groups (use with -G)
-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

CAVEATS

When changing UID, files owned by the user need to be manually updated. Use -a with -G to add groups without removing existing ones. The user must not have running processes when changing username.

HISTORY

usermod is part of the shadow-utils package for managing user accounts on Unix-like systems.

SEE ALSO

useradd(8), userdel(8), passwd(1), groupmod(8)

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community