Tags

, , , ,

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

1

( here ‘xyz’ is the username )

To view the change use  command –>

#cat /etc/passwd

2

3

2) How to create a user without home directory–

#useradd -M [username]

4

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

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

5

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

#usermod -d /var/www [username]

7

5)How to create User with account expiry date–

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

8

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

9

To modify the account date

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

10

6)How to change the user primary Group–

#usermod -g [groupname] [username]

11

7) How to change user login name–

#usermod -l [newname] [existingname]

13

 

To check ==>
#id [username]

14
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]

15

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

#usermod -p [our password] [username]

16

For encrypted password use this command–

#passwd [username]

17

10) How to change USER Shell —

#usermod -s [shell] [username]

18

11) How to change User Id (UID)–

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

19

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

#usermod -u 666 -g 514 sam1

20

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

21

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.

Read more =>

 best and easy to configure yum server in Linux??

 Telnet server configuration in Linux ??

Complete tutorial on SSH server configuration in Rhel5/Rhel6.