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:
When we execute usermod command in terminal 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 usermod -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
Share your thoughts in the comments
Please Login to comment...