🎁 New User? Get 20% off your first purchase with code NEWUSER20 Register Now →
Menu

Categories

usermod Command

Intermediate User Management man(1)

Modify a user account

👁 9 views 📅 Updated: Mar 15, 2026
SYNTAX
usermod [OPTION]... USERNAME

What Does usermod Do?

usermod modifies an existing user account. It can change the username, home directory, shell, groups, expiration date, and other account properties.

usermod requires root privileges. The most common uses are adding users to groups (-aG), changing the login shell (-s), locking/unlocking accounts (-L/-U), and changing the home directory.

The -aG flag (append to groups) is critically important — using -G without -a replaces all supplementary groups, potentially locking the user out of sudo.

Options & Flags

OptionDescriptionExample
-aG Append user to supplementary groups sudo usermod -aG docker jdoe
-s Change login shell sudo usermod -s /bin/zsh jdoe
-d Change home directory sudo usermod -d /home/newhome -m jdoe
-l Change login name sudo usermod -l newname oldname
-L Lock account (disable login) sudo usermod -L jdoe
-U Unlock account sudo usermod -U jdoe
-e Set account expiration date sudo usermod -e 2025-12-31 contractor
-g Change primary group sudo usermod -g developers jdoe
-c Change comment (full name) sudo usermod -c 'Jane Doe' jdoe

Practical Examples

#1 Add to group

Adds user to sudo group while keeping all existing groups.
$ sudo usermod -aG sudo jdoe

#2 Add to multiple groups

Adds user to docker and www-data groups.
$ sudo usermod -aG docker,www-data jdoe

#3 Change shell

Changes the default login shell to zsh.
$ sudo usermod -s /bin/zsh jdoe

#4 Lock account

Locks the account — user cannot log in. Does not kill existing sessions.
$ sudo usermod -L baduser

#5 Change home directory

Changes home directory and moves existing files (-m) to the new location.
$ sudo usermod -d /home/newhome -m jdoe

#6 Set expiration

Sets account to expire on June 30, 2025.
$ sudo usermod -e 2025-06-30 contractor

Tips & Best Practices

Always use -a with -G: usermod -G sudo user REPLACES all groups with just sudo. Always use -aG to APPEND: usermod -aG sudo user.
Verify group changes: After usermod -aG, verify with groups username or id username. User must log out/in for changes to take effect.
Lock vs delete: usermod -L locks the account (reversible with -U). userdel removes it permanently. Lock accounts for temporary disabling.

Frequently Asked Questions

How do I add a user to a group?
sudo usermod -aG groupname username. IMPORTANT: always use -a (append) with -G, or you will remove the user from all other groups.
How do I change a user shell?
sudo usermod -s /bin/zsh username. Or users can change their own shell with chsh -s /bin/zsh.
How do I lock a user account?
sudo usermod -L username locks the account. sudo usermod -U username unlocks it.

Master Linux with Professional eBooks

Curated IT eBooks covering Linux, DevOps, Cloud, and more

Browse Books →