Usermod command in Linux

Usermod command in Linux

The usermod command or modify user is a command in Linux that is used to change the properties of a user in Linux through the command line. After creating a user we have to sometimes change their attributes like password or login directory etc. so in order to do that we use the usermod command. The information of a user is stored in the following files:

  • /etc/passwd
  • /etc/group
  • /etc/shadow
  • /etc/login.defs
  • /etc/gshadow
  • /etc/login.defs
When we execute usermod command in temrinal the command make the changes in these files itself.

1. To add a comment for a user

This will add a comment about the user or a short description related to the user.

2. To change the home directory of a user

This will change the home directory of the user to /home/manav.

3. To change the expiry date of a user

This will change the expiration date of account %u201Ctest_user%u201D

4. To change the group of a user

This command will now change the group of test user from test_user to manav

5. To change user login name

This will now change the login name of the user %u201Ctest_user%u201D.

6. To lock a user

This will lock the %u201Ctest_user%u201D account and will display a! sign in shadow file before the username

7. To unlock a user