usermod is a command-line utility that allows you to modify a user’s login information.

This article covers how to use the usermod command to add a user to a group, change a user shell, login name, home directory, and more.

usermod Command

The syntax of the usermod command takes the following form:

usermod [options] USER


Only root or users with [sudo]( access can invoke usermod and modify a user account. On success, the command does not display any output.

Add a User to a Group

The most typical use case of the usermod is adding a user to a group.

To add an existing user to a secondary group, use the -a -G options followed the group’s name and the username:

usermod -a -G GROUP USER

If you want to add the user to multiple groups at once, specify the groups after the -G option separated with , (commas) with no intervening whitespace.

For example, to add the user linuxize to the games group, you would run the following command:

sudo usermod -a -G games linuxize

Always use the -a (append) option when adding a user to a new group. If you omit the -a option, the user will be removed from the groups not listed after the -G option.

If the user or group doesn’t exist, the command will warn you.

Change User Primary Group

To change a user’s primary group, invoke the usermod command with by the -g option followed the group’s name and the username:

sudo usermod -g GROUP USER

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

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 (the full name of the user) information, run the command with the -c option followed by the new comment and username:

usermod -c "GECOS Comment" USER

Here is an example showing how to add additional information to the user linuxize:

usermod -c "Test User" linuxize

This information is stored in the [/etc/passwd]( file.


Usermod Command in Linux
33.40 GEEK