Linux how to modify a user using usermod

Modifying a user on Linux can be easily done on command line using usermod. These are some scenarios and handy commands to modify a user on Linux. We’ll use Ubuntu for the purpose of this tutorial.

usermod – modify password

To create a password you can use:

$ openssl passwd -1 somepassword

To modify password

$ sudo usermod -p "$1$KNO15fOz$xMef3ieizYZmKrbhK1IAR/" user2

To validate the password we can check if the same encrypted password is present in /etc/shadow.

$ sudo cat /etc/shadow | grep user2

usermod – modify group

$ sudo usermod -g groupid_or_groupname user2

usermod – change login shell

$ sudo usermod -s /bin/bash user2

usermod – change home directory

To change home directory

$ sudo usermod --home /home/user2 user2

If the -m option is given, the contents of the current home directory will be moved to the new home directory, which is created if it does not already exist.

Share this article: share on Google+ share on facebook share on linkedin tweet this submit to reddit


Click here to write/view comments