HxHippy

usermod

Modify a user account

Overview

Modifies an existing user account. It can change most attributes of a user account specified on the command line.

Syntax

usermod [OPTION]... LOGIN

Common Options

-c comment, --comment comment

New value of the user's password file comment field.

-d home_dir, --home home_dir

New value of the user's login directory.

-e expire_date, --expiredate expire_date

The date on which the user account will be disabled.

-g initial_group, --gid initial_group

The group name or number of the user's new initial login group.

-G group,[,...], --groups group,[,...]

A list of new supplementary groups. If used with -a, append to current groups.

-a, --append

Append the user to the supplementary groups mentioned by the -G option without removing the user from other groups.

-l new_login, --login new_login

The name of the user will be changed from LOGIN to NEW_LOGIN.

-L, --lock

Lock the user's password. This puts a '!' in front of the encrypted password.

-U, --unlock

Unlock the user's password. This removes the '!' in front of the encrypted password.

-m, --move-home

Move the content of the user's home directory to the new location (use with -d).

-s shell, --shell shell

The name of the user's new login shell.

-u uid, --uid uid

New numerical value of the user's ID.

Examples

$ sudo usermod -c "Johnathan Doe" jdoe

Updates the comment (full name) for user jdoe.

$ sudo usermod -s /bin/zsh jdoe

Changes jdoe's login shell to zsh.

$ sudo usermod -aG sudo,www-data jdoe

Adds jdoe to the sudo and www-data supplementary groups (without removing existing ones).

$ sudo usermod -l newname oldname

Renames user oldname to newname.

$ sudo usermod -L tempuser

Locks the tempuser account.

$ sudo usermod -U tempuser

Unlocks the tempuser account.

$ sudo usermod -d /home/new_home -m jdoe

Moves jdoe's home directory to /home/new_home and updates login details.

$ sudo usermod -e 2025-01-01 contractor

Sets an expiry date for the contractor account.

useraccountmodifychangeupdateloginusermod