The usermod
command lets you change the properties of a user in Linux through the command line. After creating a user we sometimes have to change their attributes, like their password or login directory etc. So in order to do that we use the usermod
command.
usermod [options] USER
Option | Description |
---|---|
-a |
to add anyone of the group to a secondary group |
-c |
to add comment field for the useraccount |
-d |
to modify the directory for any existing user account |
-g |
change the primary group for a User |
-G |
to add supplementary groups |
-l |
to change existing user login name |
-L |
to lock system user account |
-m |
to move the contents of the home directory from existing home dir to new dir |
-p |
to create an un-encrypted password |
-s |
to create a specified shell for new accounts |
-u |
to assigned UID for the user account |
-U |
to unlock any locked user |
- To add a comment/description for a user:
sudo usermod -c "This is test user" test_user
- To change the home directory of a user:
sudo usermod -d /home/sam test_user
- To change the expiry date of a user:
sudo usermod -e 2021-10-05 test_user
- To change the group of a user:
sudo usermod -g sam test_user
- To change user login name:
sudo usermod -l test_account test_user
- To lock a user:
sudo usermod -L test_user
- To unlock a user:
sudo usermod -U test_user
- To set an unencrypted password for the user:
sudo usermod -p test_password test_user
- To create a shell for the user:
sudo usermod -s /bin/sh test_user
- To change the user id of a user:
sudo usermod -u 1234 test_user