usermod Command: Tutorial & Examples

Modifying users

The usermod command is a system command used in Unix/Linux systems for modifying a user's system account. This command modifies the system account files to reflect the changes that are specified on the command line. It's an essential tool for system administrators, allowing them to manage user accounts effectively.

Importance of usermod Command

The usermod command is a powerful utility that allows for diverse modifications to a user account. It is used for tasks like moving a user's home directory, changing a user's login name or UID, locking or unlocking user accounts, and adding a user to supplementary groups. Understanding how to use usermod can be a key to efficient system administration and troubleshooting.

Common usermod Command Parameters

Here are some common parameters used with the usermod command:

  • -l, --login NEW_LOGIN : The name of the user will be changed from LOGIN to NEW_LOGIN.
  • -u, --uid UID : The numerical value of the user's ID will be changed to UID.
  • -g, --gid GROUP : The user's initial login group will be changed to GROUP.
  • -d, --home HOME_DIR : The user's home directory will be changed to HOME_DIR.
  • -e, --expiredate EXPIRE_DATE : The date of user account expiration is changed.

Examples of Using usermod Command

Here are some basic examples of using the usermod command.

  1. Change the user's login name:

    usermod -l newname oldname
    

    In this example, the user's login name is changed from 'oldname' to 'newname'.

  2. Change the user's home directory:

    usermod -d /new/home/dir username
    

    In this example, the user's home directory is changed to '/new/home/dir'.

  3. Add a user to an additional group:

    usermod -aG groupname username
    

    In this example, the user is added to the 'groupname' group.

  4. Change the user's account expiration date:

    usermod -e 2022-12-31 username
    

    In this example, the user's account expiration date is set to '2022-12-31'.

  5. Disable an account temporarily:

    usermod -L username
    

This will lock 'username's account, preventing them from logging in.

Conclusion

The usermod command is an essential tool for managing user accounts on a Unix/Linux system. By understanding the various parameters and options available with this command, you can efficiently manage and troubleshoot user accounts on your system. Remember to use this command with caution, as improper use can result in changes that may be difficult to reverse.

The text above is licensed under CC BY-SA 4.0 CC BY SA