The usermod command is used to modify settings for regular users. It edits the /etc/passwd file, avoiding the need for administrators to edit the file directly. There are many modifications an administrator can make to an existing user account.
Syntax
The syntax of the usermod command is:
# usermod [options] {user name}
usermod command options
The below table lists some options for the usermod command.
Option | Description | Example |
---|---|---|
-c | Sets Comment Field | # usermod -c “User one” user01 |
-e | Sets account expiration date | # usermod -e 2021/12/31 |
-aG | Add user to group, keeping them in existing groups. | # usermod -aG sales-group user01 |
-l | Change user’s login name | # usermod -l user999 user01 |
usermod Command Examples
1. To modify the users comment:
# usermod -c "test User"
2. To change the users home directory:
# usermod -d /home/test geek
3. To change the users expiry date:
# usermod -e 2013-12-31 geek
4. To change the inactivity day number, before expiry:
# usermod -f 2 geek
5. To change the primary group of the user:
# usermod -g UNIX geek
6. To change/add the secondary groups to the user:
# usermod -G logistics,IT geek
7. To change the name of the user:
# usermod -l geeklab jack
8. To lock the user password:
# usermod -L geek
9. To unlock the user password:
# usermod -U
10. To change the shell of the user:
# usermod -s /bin/csh geek
11. To change the users ID:
# usermod -u 580 geek