usermod Command in Linux: Modify User Accounts and Groups

By 

Updated on

8 min read

usermod command

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:

txt
usermod [OPTIONS] USER

On 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:

Terminal
usermod -a -G GROUP USER

To 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:

Terminal
sudo usermod -a -G games linuxize

Always 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:

Terminal
id linuxize

If 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:

Terminal
sudo usermod -g GROUP USER

In the following example, we are changing the primary group of the user linuxize to developers:

Terminal
sudo usermod -g developers linuxize

Each 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:

Terminal
usermod -c "GECOS Comment" USER

Here is an example showing how to add a description to the user linuxize:

Terminal
sudo usermod -c "Test User" linuxize

This 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:

Terminal
usermod -d HOME_DIR USER

By 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:

Terminal
usermod -d HOME_DIR -m USER

Here is an example showing how to change the home directory of the user www-data to /var/www:

Terminal
sudo usermod -d /var/www www-data

Changing 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:

Terminal
usermod -s SHELL USER

In the following example, we are changing the login shell to Zsh:

Terminal
sudo usermod -s /usr/bin/zsh linuxize

You 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:

Terminal
usermod -u UID USER

The following example changes the UID of linuxize to 1050:

Terminal
sudo usermod -u 1050 linuxize

The 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:

Terminal
usermod -l NEW_USER USER

In the following example, we are renaming the user linuxize to leah:

Terminal
sudo usermod -l leah linuxize

When renaming a user, you may also want to rename the home directory to match. Use -d together with -m to move it:

Terminal
sudo usermod -l leah -d /home/leah -m linuxize

To 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:

Terminal
sudo usermod -e DATE USER

The date must use the format YYYY-MM-DD.

For example, to disable the user linuxize on 2026-12-31:

Terminal
sudo usermod -e "2026-12-31" linuxize

To remove the expiry date and keep the account active indefinitely, set an empty string:

Terminal
sudo usermod -e "" linuxize

Use the chage -l command to confirm the expiry date:

Terminal
sudo chage -l linuxize
output
Last 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       : 7

The 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:

Terminal
sudo usermod -L linuxize

To lock the account completely and disable all login methods, combine -L with an expiry date of 1:

Terminal
sudo usermod -L -e 1 linuxize

To unlock a user account, use the -U option:

Terminal
sudo usermod -U USER

For password management options, see How to Change User Password in Linux .

Quick Reference

CommandDescription
usermod -a -G GROUP USERAdd user to a secondary group
usermod -g GROUP USERChange primary group
usermod -c "TEXT" USERSet GECOS comment field
usermod -d DIR USERChange home directory
usermod -d DIR -m USERChange and move home directory contents
usermod -s SHELL USERChange default shell
usermod -u UID USERChange user UID
usermod -l NEW_USER USERRename user
usermod -e YYYY-MM-DD USERSet account expiry date
usermod -e "" USERRemove account expiry date
usermod -L USERLock account (disable password login)
usermod -U USERUnlock 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.

Linuxize Weekly Newsletter

A quick weekly roundup of new tutorials, news, and tips.

About the authors

Dejan Panovski

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