Linux usermod command with examples

Linux usermod command with examples

usermod command is used to change the attribute of already exist user account. The command useradd is used to create new user in Linux system. for creating a user you can simply write the username after useradd command. In case you need to change the attribute of user than use the usermod command. The information of a user is stored in /etc/passwd file in Linux/Unix system. User information includes user ID [UID], username, Group Id [GID], shell details, location of home directory etc. you can use the different option for changing the attributes with usermod command.

Syntax:

# usermod [options] USERNAME

Usermod Options:

· -d: this option is used to change the directory of user account.

· -c : this option us used to add brief information to already exist user account.

· - e: this option is used to change the expiry date of user account.

· - g: this option is used to change the group of existing user.

· - G : adding supplementary group to user.

· - a: this option is used to adding any user of group to the secondary group.

· -L:you can lock user account.

· -l: used for changing the login name.

· -p:used to un_encrypted password for new password.

· -m: used to move the content from one [home] directory to another location.

· -s: used to create new shell for user account.

· -u: this option for set user ID for user account.

· -U: used for unlock the account of user.


Usermod commands with example:

1. Change Home Directory of User:

The home directory is found below the /home/tecmint. If you want to change the home directory of already exist user than you can use the following command. For instance you can change the directory with /var/www/. So before change the directory you have to check the current directory of user by using the given command.

Syntax:

# grep – E - - color ‘/home/tec’ /etc/passwd


After that you can change the directory using the following command

Syntax:

# usermod – d /var/www/ tecmint.

# grep – E - - color ‘/var/www’ /etc/passwd



2. Add information to User Account:

If you want to add the brief comment or information of user account then use the given command

Syntax:

# usermod – c “tecmint is name of user” tecmint.


3. Set Expiry Date of User Account:

You can set the expiry date of user account using the – e option. Before set the expiry date on the user check the current status of expiry date using the “chage” command.

# chage – 1 tecmint

It will shows the account expiry date of tecmint user for instance the expiry date of account is 25 nov 2015 then you can change it by 25 jan 2015 via using the – e option with usermod command.

Syntax:

# usermod – e 2015-01-25 tec

# chage – 1 tec


By suing the chage command you can confirm the chage expiry date.


4. Alter primary group of User:

If you want to change the primary group of user then uses the – g option with usermod command.For change the group first you have to check the current group. By use the given command.

Syntax:

# id tecmint_emp

After that you can change the group barban as a primary group using the given command. And confirm after changing that group is changed or not.

Syntax:

# usermod – g barban tecmint_emp

# id tecmint_emp

5. Add new group to Existing User:

If you want to add the new group to an existing user then uses the – G option with usermod command.

Syntax:

# usermod – G groupname username

# id username

6. Changing the login Name of User:

If you want to change the login name of existing user than you can use the – l option with usermod command.

Syntax:

# usermod – l <new login name> <old login name>

# usermod – l tecmint_admin tecmint


7. Locked User Account:

If you want to lock the user account then you can use the – L option with usermod command. When you lock the account then you can’t login and you will see the (!) sign before encrypted password.

Syntax:

# usermod –L < primary groupname>

# usermod – L barban

8. Unlock user Account:

If you want to unlock the user account you can use the – U option with usermod command.

Syntax:

# usermod – U <primary groupname>

# usermod – U barban


You can verify that you account is unlocked or not using given syntax.


# grep – E - -color ‘barban’ /etc/shadow.

9. Creating Un_encrypted password:

For creating an un_encrypted password use the –p option with usermod command.

Syntax:

# usermod – p <password> <username>

# usermod – p redhat tec


10.Changing User ID:

If you want to change the user id to existing user id than use the – u option with usermod command. You can take the user id number between 0 to 999. For instance the user id of a user is 512 and you want to change it with 789.

Syntax:

# usermod – u <new UID> <username>

# usermod – u 789 tec

# id tec
Author
Jaishree
First release
Last update
Rating
0.00 star(s) 0 ratings
Top