Linux usermod command

The “usermod” command in Linux is used to modify user account properties and settings. It allows system administrators to change various attributes of an existing user account, such as the username, user ID (UID), group ID (GID), home directory, login shell, and more.

Here is the basic syntax of the “usermod” command:

usermod [options] username

Here’s a practical example of how to use the “usermod” command:

  1. Change the username of a user:
   sudo usermod -l newusername oldusername

Replace “newusername” with the desired new username and “oldusername” with the current username. This command changes the username of the specified user to the new value.

Example:

   $ sudo usermod -l johnsmith john

In this example, the “usermod” command changes the username of the user “john” to “johnsmith”.

  1. Change the home directory of a user:
   sudo usermod -d /new/home/directory username

Replace “/new/home/directory” with the desired path to the new home directory and “username” with the username of the user. This command modifies the home directory location for the specified user.

Example:

   $ sudo usermod -d /home/johnsmith john

In this example, the “usermod” command changes the home directory of the user “john” to “/home/johnsmith”.

  1. Add a user to a supplementary group:
   sudo usermod -aG groupname username

Replace “groupname” with the name of the supplementary group and “username” with the username of the user. This command adds the user to the specified supplementary group.

Example:

   $ sudo usermod -aG developers john

In this example, the “usermod” command adds the user “john” to the supplementary group “developers”.

These are just a few examples of how the “usermod” command can be used to modify user account properties. The “usermod” command offers a wide range of options and can be used to make various changes to user accounts, including modifying UID, GID, login shell, expiration date, and more. Use the appropriate options based on the changes you want to make and ensure that you have the necessary administrative privileges to modify user accounts.