, , , ,

usermod command in linux
hi friends i am back with 2nd tutorial on user  management in Linux. In previous tutorial we learn some basic fundamentals about users and groups .

If you are new to Linux then i reccommand to read it first =>User and group management in Linux. In 1st tutorial we learn how to create, delete,enable,disable a user and also dig into basics of group management. Today in this tutorial we will learn some advance stuff related to user management in Linux. After reading this tutorial you have a good knowledge related to users in Linux.

So let’s get started

Usermod in Linux

When we need to change the attributes of an existing user such as, change user’s home directory, login name, login shell, password expiry date, etc then it requires a special command named as usermod command.

when we execute or run the ‘usermod’ command then the following files are affected =>

–> /etc/passwd -> User account information.
–> /etc/shadow -> Secure account information.
–> /etc/group -> Group account information.
–> /etc/gshadow -> Secure account information.
–> /etc/login.defs ->Shadow password suite configuration..

The Basic syntx of usermod command:-

usermod   [option]   username

Options that can be used with usermod command–

-c = We can add comment for the useraccount.
-d = To modify the directory of any existing user account.
-e = To make the account expiry in specific period.
-g = To change the primary group of a User.
-G = To add a supplementary groups.
-a = To add anyone of the group to a secondary group.
-l = To change the login name.
-L = To lock the user account.
-m = To move the contents of the home directory from existing home directory to new directory.
-p = To Use un-encrypted password for the new password.
-s = To create a specified shell for new accounts.
-u = This is used to assign UID for the user account between 0 to 999.
-U = To unlock the user accounts.

Important Usermod commands in Linux

1) How to add information or comment to user account–

#usermod -c “This is helping u online ” xyz


( here ‘xyz’ is the username )

To view the change use  command –>

#cat /etc/passwd



2) How to create a user without home directory–

#useradd -M [username]


3) How to add the user with specific home directory —

#useradd -M -d /var/www [username]


4) How to change the home directory of an existing User to new location —

#usermod -d /var/www [username]


5)How to create User with account expiry date–

#useradd -e 2015-11-30 [username]


To check ==>
#chage -l [username]


To modify the account date

#usermod -e 2020-11-30 [username]


6)How to change the user primary Group–

#usermod -g [groupname] [username]


7) How to change user login name–

#usermod -l [newname] [existingname]



To check ==>
#id [username]

here the name will change but the UID and GID will same.

8) How to move the home directory of an existing User to new location —

#usermod -d /var/www -m [username]


9)How to create Un-encrypted Password for an user.

#usermod -p [our password] [username]


For encrypted password use this command–

#passwd [username]


10) How to change USER Shell —

#usermod -s [shell] [username]


11) How to change User Id (UID)–

#usermod -u [userid between 0 to 999] [username]
e.g. # usermod -u 888 sam1


13) How to change User Id (UID) and Group Id (GID) of a user–

#usermod -u 666 -g 514 sam1


14) How to Modify user account with multiple options —

#usermod -d /var/www/html/ -s /bin/bash -e 2020-12-10 -c “This is user sam1” -u 666 -aG jaipur sam1


so the ‘sam1’ user’s default directory will change to /var/www/html and assign his shell as bash, set expiry date as December 10th 2020, and new comment as ‘This is user’ and change UID to 666 and sam will be the member of jaipur group.

Hope you like this article, feel free to comment if you have any doubt & do follow our blog and don’t forget to share this article on Facebook, twitter.


 best and easy to configure yum server in Linux??

 Telnet server configuration in Linux ??

Complete tutorial on SSH server configuration in Rhel5/Rhel6.