Usermod Command
What is the Usermod Command?
The usermod command is used to modify an existing user's properties on a Linux system. You can change a user's username, password, group membership, home directory, login shell, and more.
How Does It Work?
When you use the usermod command, you specify the options for the changes you wish to make to an existing user account. This allows you to customize user settings, making it an important tool for system administrators.
Syntax:
usermod [options] username
Common Options
Here are some commonly used options with the usermod command:
- -l: Change the username.
- -d: Specify a new home directory for the user.
- -m: Move the user's files to the new home directory.
- -g: Change the primary group of the user.
- -a -G: Add the user to an additional group.
- -s: Change the user's default login shell.
Examples of Using the Usermod Command
Here are some practical examples of how to use the usermod command:
To change the username of a user from "john" to "johnny":
$ usermod -l johnny john
To change the home directory of "alice" to "/home/alice_new" and move the files:
$ usermod -d /home/alice_new -m alice
To add the user "bob" to an additional group "developers":
$ usermod -a -G developers bob
Visual Example
Learn more about user modifications below: