Linux: Set user password by using encrypted password in command

In this tutorial we will learn about how to set user password by using encrypted password in command line.We assume you already know about how to simply set/reset password of user by using command (passwd username). In this tutorial,first we will encrypt the password in python interpreter then we use the output in one liner command.
You can use this method in scripts and as per scenarios.

Set user password by using encrypted password in command,follow the given below steps

Step 1: Login with root or become a super user

sudo su -

Step 2: Create a user.If you already have user then skip this step

useradd user-name


useradd sharad

Step 3: Now we will get encrypted password by using python interpreter

=> Run the command python and you will get python interpreter

=> Now type below given line and replace give-your-password with your new password

import crypt; print crypt.crypt("","")

After this you will get the output. Copy the output and save it in some file.

=> To exit from python interpreter ,press CTRL+D to exit

Encrypted password

Step 4: Now paste the output in below given command

usermod -p "Encrypted-Password-OUTPUT" user-name


usermod -p "

set encrypted password

Now try login with username whose password you have changed.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.