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 infomration 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.
Note: usermod command needs to be executed only as a root user.
Working with usermod command
1. To add a comment for a user
sudo usermod -c "This is test user" test_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
sudo usermode -d /home/manav test_user

This will change the home directory of the user to /home/manav.
3. To change the expiry date of a user
sudo usermod -e 2020-05-29 test_user

This will change the expiration date of account “test_user”
4. To change the group of a user
sudo usermod -g manav test_user

This command will now change the group of test user from test_user to manav
5. To change user login name
sudo usermod -l test_account test_user

This will now change the login name of the user “test_user”.
6. To lock a user
sudo usermod -L test_user

This will lock the “test_user” account and will display a! sign in shadow file before the username
7. To unlock a user
sudo usermod -U test_user

This will unlock the “test_user” which was locked by the previous command
8. To set an unencrypted password for the user
sudo usermod -p test_password test_user

This will set the password “test_password” in the unencrypted form for the user “test_user”
9. To create a shell for the user
sudo usermod -s /bin/sh test_user

This command will now create a shell for the user “test_user” from /bin/sh
10. To change the user id of a user
sudo usermod -u 1234 test_user

This command will change the user id of “test_user” to 1234
Recommended Posts:
- gs command in Linux with Examples
- gcc command in Linux with examples
- fmt command in Linux with examples
- yes command in Linux with Examples
- cd command in Linux with Examples
- dir command in Linux with examples
- top command in Linux with Examples
- tar command in Linux with examples
- ssh command in Linux with Examples
- bc command in Linux with examples
- cal command in Linux with Examples
- which command in Linux with examples
- ex command in Linux with examples
- ln command in Linux with Examples
- mv command in Linux with examples
- let command in Linux with Examples
- apt-get command in Linux with Examples
- look command in Linux with Examples
- ip command in Linux with examples
- ar command in Linux with examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

