Usermod Command in Unix-like Systems

Usermod Command in Unix-like Systems

Comprehensive Guide

In Unix-like operating systems, effective user management is crucial. Among all commands available, usermod command is used to modifying user account properties. In this comprehensive guide, we sive deep into the usermod command and exploring its various options with example

  1. -c, --comment COMMENT: Add a comment to the user account.

     usermod -c "John Doe" username
    

    This command adds a comment "John Doe" to the user account with the username "username".

  2. -d, --home HOME_DIR: Set the user's home directory.

     usermod -d /home/newhome username
    

    This command changes the home directory of the user with the username "username" to "/home/newhome".

  3. -e, --expiredate EXPIRE_DATE: Set the account expiration date.

     usermod -e 2024-12-31 username
    

    This command sets the account expiration date for the user with the username "username" to December 31, 2024.

  4. -f, --inactive INACTIVE: Set the number of inactive days before an account is disabled.

     usermod -f 30 username
    

    This command sets the number of inactive days to 30 before the account for the user with the username "username" is disabled.

  1. -g, --gid GROUP: Set the user's primary group.

     usermod -g newgroup username
    

    This command changes the primary group of the user with the username "username" to "newgroup".

  2. -G, --groups GROUPS: Add the user to additional groups.

     usermod -G group1,group2 username
    

    This command adds the user with the username "username" to the additional groups "group1" and "group2".

  3. -a, --append: Add the user to the supplementary group(s), in addition to the current group(s).

     usermod -aG supplementarygroup username
    

    This command adds the user with the username "username" to the supplementary group "supplementarygroup" without removing them from their current group(s).

  4. -h, --help: Display help message and exit.

     usermod --help
    

    This command displays the help message for the usermod command, providing information on its usage and options.

  5. -l, --login NEW_LOGIN: Change the login name of the user.

     usermod -l newusername oldusername
    

    This command changes the login name of the user from "oldusername" to "newusername".

  6. -L, --lock: Lock the user account.

     usermod -L username
    

    This command locks the account of the user with the username "username", preventing them from logging in.

  7. -m, --move-home: Move the content of the user's home directory to the new location.

     usermod -m -d /newhome username
    

    This command moves the content of the user's home directory to a new location "/newhome" and updates the home directory path.

  8. -o, --non-unique: Allow using a non-unique UID.

     usermod -o -u 1001 username
    

    This command allows the user with the username "username" to have a non-unique UID (user ID) by specifying the -o option.

  9. -p, --password PASSWORD: Set the user's password to the specified encrypted password.

     usermod -p '$6$DmQX4M8E$6OAl6DSAX1Yv2y3FyDpE11WEdM/7D1AUViWfQTowqVg6GwxjcA3xjZpM0gibklW77ZftXMHxvUvWbuP3CJg.1' username
    

    This command sets the user's password to the specified encrypted password.

  10. -s, --shell SHELL: Set the user's login shell.

    usermod -s /bin/bash username
    

    This command changes the login shell of the user with the username "username" to "/bin/bash".

  11. -u, --uid UID: Set the user's UID (user ID).

    usermod -u 1001 username
    

    This command changes the UID (user ID) of the user with the username "username" to 1001.

  12. -U, --unlock: Unlock the user account.

    usermod -U username
    

    This command unlocks the previously locked account of the user with the username "username", allowing them to log in again.