How to use usermod command on Ubuntu Linux with examples

|

|

The ‘usermod’ command allows Linux system administrators to change user account settings. It can be utilized to update account names, assign or modify comments, define new home directories, manage password inactivity, and more. Ubuntu is a user-friendly, open-source Linux operating system which is a great starting point for those learning about commands like ‘usermod’. Various…

The usermod command is used by system administrators to change users’ account settings, similar to the passwd command.

The usermod command is a useful tool for system administrators who must manage and modify user accounts on Ubuntu Linux. It allows you to change various settings associated with user accounts, such as the account’s home directory, login name, and group membership, among other things.

By using usermod, you can quickly and easily modify user accounts without having to create new accounts or manually change settings in configuration files.

Overall, the usermod command is essential for managing user accounts on Ubuntu Linux, and it can save system administrators a lot of time and effort.

When you’re ready to learn how to use the usermod commands, follow the guide below:

About usermod command:

The usermod command is used by system administrators to change users’ account settings, similar to the passwd command. Like using your mouse and keyboard to change account settings in the GUI., the usermod is the way to do it on the command line.

Syntax:

The syntax is the rule and format of how the usermod command can be used. The syntax options can be reordered. But a straight format must be followed.

Below is an example syntax of how to use the usermod command.

usermod [OPTION]. LOGIN.

Options:

The command line options are switches or flags that determine how the commands are executed or controlled. They modify the behavior of the command. They are separated by spaces and followed after the command’s options.

Below are some options for the usermod command:

LOGIN.Replace LOGIN .. with the account’s name if you want to change its settings. If the account doesn’t already exist, the command will fail and not execute.
-c, –comment COMMENT
Use the -c or –command COMMENT option to set or change the user’s account comment field.
-d, –home HOME_DIRUse the -d or –home HOME_DIR option to change or set a new home directory for the user account.
-f, –inactive INACTIVEUse the -f or –inactive INACTIVE option to set password inactive after expiration to INACTIVE
 -g, –gid GROUPUse the -g or –gid GROUP option to force use GROUP as new primary group
-G, –groups GROUPSUse the -G or –groups GROUP option to set new list of supplementary GROUPS
-a, –append  Use the -a or –append option to append the user to the supplemental GROUPS
-l, –login NEW_LOGIN Use the -l or –login NEW_LOGIN option to create new value of the login name
-h, –help Display help message and exit.
-L, –lock Use the -L or –lock option to lock the user account

Examples:

Below are some examples of how to run and use the usermod on Ubuntu Linux.

If you want to add an account name, John, to the sudo group, run the commands below.

usermod -a -G sudo john

If you wish to change John’s account’s full name or comment field, run the usermod command and specify John’s account name. In this case, it’s called John.

usermod -c "John Doe" john

If you’re not logged in as a root account, you may have to use the sudo command.

sudo usermod -c "John Doe" john

To change John’s account login name to paul, run the commands below.

sudo usermod -l paul john

To unlock John’s account, run the command below

sudo usermod -U john

To lock John’s account, run the commands below.

sudo usermod -L john

To change John’s home directory, run the commands below

sudo usermod -d /home/newHomeDir -m johnNewHome

When you run usermod with the –help option, you’ll see the help text below:

Usage: usermod [options] LOGIN

Options:
  -c, --comment COMMENT         new value of the GECOS field
  -d, --home HOME_DIR           new home directory for the user account
  -e, --expiredate EXPIRE_DATE  set account expiration date to EXPIRE_DATE
  -f, --inactive INACTIVE       set password inactive after expiration
                                to INACTIVE
  -g, --gid GROUP               force use GROUP as new primary group
  -G, --groups GROUPS           new list of supplementary GROUPS

That’s it!

I hope you like it, and please come back soon for more Ubuntu Linux commands!

Like this:



One response to “How to use usermod command on Ubuntu Linux with examples”

  1. Juan Avatar
    Juan

    Thxs

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.