The usermod command

modify a user account 7 examples from the lessons of the IVski Linux Playground — try them in the terminal next to them.

Options in the examples

-a, --append
Add the user to the supplementary group(s).
-G, --groups GROUP1[,GROUP2,...[,GROUPN]]]
A list of supplementary groups which the user is also a member of.
-L, --lock
Lock a user's password. This puts a '!' in front of the encrypted password, effectively disabling the password.
-l, --login NEW_LOGIN
The name of the user will be changed from LOGIN to NEW_LOGIN.
-s, --shell SHELL
changes the user's login shell. An empty string for SHELL blanks the field in /etc/passwd and logs the user into the system's default shell.
-U, --unlock
Unlock a user's password. This removes the '!' in front of the encrypted password.

Examples

sudo usermod -aG sudo username

Add to sudo group

sudo usermod -s /bin/zsh username

Change shell

sudo usermod -l newname oldname

Rename user

sudo usermod -L username

Lock account

sudo usermod -U username

Unlock account

usermod -aG developers NAME

Into the group, keeping the others (-a)

sudo usermod -aG sudo ana

Grant sudo access

Lessons that use usermod