usermod Command in Linux: Modify User Accounts and Groups

usermod is a command-line utility for modifying user account attributes. You can use it to add a user to a group, change the default shell, rename a user, set an expiry date, lock or unlock an account, and more.
Only root or users with sudo
access can invoke usermod. To create new users, see useradd
. To remove users, see userdel
.
usermod Command Syntax
The syntax of the usermod command takes the following form:
usermod [OPTIONS] USEROn success, the command does not display any output.
Add a User to a Group
The most common use of usermod is adding a user to a secondary group. Use the -a -G options followed by the group name and the username:
usermod -a -G GROUP USERTo add the user to multiple groups at once, specify the groups after -G as a comma-separated list with no spaces.
For example, to add the user linuxize to the games group:
sudo usermod -a -G games linuxizeAlways use the -a (append) option when adding a user to a new group. If you omit -a, the user will be removed from every group not listed after -G.
To verify the change, run:
id linuxizeIf the user or group does not exist, the command will display a warning. For more on managing groups, see How to Add a User to a Group in Linux and How to Create Groups in Linux .
Change User Primary Group
To change a user’s primary group, use the -g option followed by the group name and the username:
sudo usermod -g GROUP USERIn the following example, we are changing the primary group of the user linuxize to developers:
sudo usermod -g developers linuxizeEach user can belong to exactly one primary group and zero or more secondary groups.
Changing the User Information
To change the GECOS field (the full name or description of the user), run the command with the -c option followed by the new comment and the username:
usermod -c "GECOS Comment" USERHere is an example showing how to add a description to the user linuxize:
sudo usermod -c "Test User" linuxizeThis information is stored in the /etc/passwd
file.
Changing a User Home Directory
On most Linux systems, user home directories are named after the username and created under /home.
To change the home directory, use the -d option followed by the absolute path of the new directory and the username:
usermod -d HOME_DIR USERBy default, the command does not move the contents of the old home directory to the new one. To move the contents, add the -m option. If the new directory does not already exist, it is created:
usermod -d HOME_DIR -m USERHere is an example showing how to change the home directory of the user www-data to /var/www:
sudo usermod -d /var/www www-dataChanging a User Default Shell
The default shell is the shell that starts when you log in to the system. On most Linux systems, the default shell is Bash.
To change the default shell, use the -s option followed by the absolute path of the shell and the username:
usermod -s SHELL USERIn the following example, we are changing the login shell to Zsh:
sudo usermod -s /usr/bin/zsh linuxizeYou can view the shells available on your system by reading the /etc/shells file.
Changing a User UID
The UID (user identifier) is a number assigned to each user that the operating system uses to identify that user internally.
To change the UID, use the -u option followed by the new UID and the username:
usermod -u UID USERThe following example changes the UID of linuxize to 1050:
sudo usermod -u 1050 linuxizeThe UID of files owned by the user and located in the user’s home directory and mailbox will be updated automatically. The ownership of all other files must be changed manually.
Changing a User Name
To rename an existing user, use the -l option. The new username is specified first, followed by the current username:
usermod -l NEW_USER USERIn the following example, we are renaming the user linuxize to leah:
sudo usermod -l leah linuxizeWhen renaming a user, you may also want to rename the home directory to match. Use -d together with -m to move it:
sudo usermod -l leah -d /home/leah -m linuxizeTo verify the rename, see How to List Users in Linux .
Setting a User Expiry Date
The expiry date is the date on which the user account will be disabled. To set the expiry date, use the -e option followed by the date and the username:
sudo usermod -e DATE USERThe date must use the format YYYY-MM-DD.
For example, to disable the user linuxize on 2026-12-31:
sudo usermod -e "2026-12-31" linuxizeTo remove the expiry date and keep the account active indefinitely, set an empty string:
sudo usermod -e "" linuxizeUse the chage -l command to confirm the expiry date:
sudo chage -l linuxizeLast password change : Jul 24, 2018
Password expires : never
Password inactive : never
Account expires : never
Minimum number of days between password change : 0
Maximum number of days between password change : 99999
Number of days of warning before password expires : 7The expiration date is stored in the /etc/shadow
file.
Locking and Unlocking a User Account
The -L option locks a user account by inserting an exclamation point (!) in front of the encrypted password in /etc/shadow. This prevents password-based logins, but other methods such as SSH key-based authentication
or switching users with su
remain active.
To lock only the password:
sudo usermod -L linuxizeTo lock the account completely and disable all login methods, combine -L with an expiry date of 1:
sudo usermod -L -e 1 linuxizeTo unlock a user account, use the -U option:
sudo usermod -U USERFor password management options, see How to Change User Password in Linux .
Quick Reference
| Command | Description |
|---|---|
usermod -a -G GROUP USER | Add user to a secondary group |
usermod -g GROUP USER | Change primary group |
usermod -c "TEXT" USER | Set GECOS comment field |
usermod -d DIR USER | Change home directory |
usermod -d DIR -m USER | Change and move home directory contents |
usermod -s SHELL USER | Change default shell |
usermod -u UID USER | Change user UID |
usermod -l NEW_USER USER | Rename user |
usermod -e YYYY-MM-DD USER | Set account expiry date |
usermod -e "" USER | Remove account expiry date |
usermod -L USER | Lock account (disable password login) |
usermod -U USER | Unlock account |
Troubleshooting
User is removed from all groups after running usermod -G
You omitted the -a flag. Without -a, the -G option replaces the user’s group list entirely. Always use -a -G together when adding to a group: usermod -a -G GROUP USER.
Wrong argument order with -l
The new username must come before the old username: usermod -l NEW_NAME OLD_NAME. Reversing the order will rename the wrong account or produce an error.
usermod: user USER is currently used by process PID error
The user is logged in or a process is running under that account. Log the user out and stop any associated processes before modifying the account.
UID conflict error when using -u
The UID you specified is already assigned to another user. Choose a UID that is not in use, or check existing UIDs with getent passwd | cut -d: -f3 | sort -n.
FAQ
What is the difference between -g and -G?-g changes the user’s primary group — the group assigned to new files by default. -G sets the list of supplementary groups. Always pair -G with -a to add to the list without replacing it.
What happens if I omit -a when using -G?
The user is removed from all groups not listed in the -G argument. This can silently revoke access to services and shared directories. Always use -a -G to append.
How do I verify changes made by usermod?
Use id USERNAME to check UID, primary group, and supplementary groups. Use grep USERNAME /etc/passwd to check the shell and home directory. Use sudo chage -l USERNAME to review expiry settings. See How to List Users in Linux
and How to List Groups in Linux
for more options.
Can I change multiple settings in one command?
Yes. You can combine multiple options in a single usermod call. For example, to rename a user and move the home directory at the same time: usermod -l leah -d /home/leah -m linuxize.
What is the difference between locking with -L and setting an expiry date?-L only disables password authentication. The account can still be accessed via SSH keys or su. Setting the expiry date to 1 with -e 1 disables all login methods regardless of authentication type.
Conclusion
The usermod command covers nearly all common user account modifications — group membership, shell, home directory, UID, username, expiry, and account locking. Use id and chage -l after each change to verify the result.
If you have any questions, feel free to leave a comment below.
Tags
Linuxize Weekly Newsletter
A quick weekly roundup of new tutorials, news, and tips.
About the authors

Dejan Panovski
Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 800+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.
View author page