Enhancing Skills

usermod: Modify a user account

Command: usermod

The usermod command allows administrators to modify a user’s account details, such as changing the user’s home directory, adding the user to groups, or changing the user’s login name. This command requires superuser (root) privileges.


Sample Commands and Outputs:

  • usermod -aG groupname username: Adds a user to a group. Sample Command and Output:
  $ sudo usermod -aG developers user1

Description:

  • -aG: Appends the user to the specified group(s) without removing them from other groups.
  • developers: The name of the group to which the user is being added.
  • user1: The username of the account being modified.
  • usermod -d /new/home/dir username: Changes the user’s home directory. Sample Command and Output:
  $ sudo usermod -d /home/user1_new user1

Description:

  • -d /new/home/dir: Specifies the new home directory for the user.
  • /home/user1_new: The new home directory.
  • user1: The username of the account being modified.
  • usermod -l newusername oldusername: Changes the username. Sample Command and Output:
  $ sudo usermod -l newuser olduser

Description:

  • -l newusername: Specifies the new login name.
  • newuser: The new username.
  • olduser: The current username that is being changed.
  • usermod -s /bin/zsh username: Changes the user’s default shell. Sample Command and Output:
  $ sudo usermod -s /bin/zsh user1

Description:

  • -s /bin/zsh: Specifies the new default shell for the user.
  • /bin/zsh: The path to the new default shell.
  • user1: The username of the account being modified.
  • usermod -e 2024-12-31 username: Sets an expiration date for the user account. Sample Command and Output:
  $ sudo usermod -e 2024-12-31 user1

Description:

  • -e 2024-12-31: Specifies the expiration date for the user account in YYYY-MM-DD format.
  • user1: The username of the account being modified.

Note: The usermod command is a powerful tool for system administrators to manage user accounts and should be used with caution to ensure proper configuration and security of user accounts.


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.