In this post we will see how to set a password for an user. Once the user is created we have to set a password for the account, if we do not set it user will not be able to login. Below steps shows the steps in setting a password for an user.

Step 1 : Check if user password is set or not.

grep username /etc/shadow

Example

root@linuxnix.com:/home/surendra# grep kumar /etc/shadow
kumar:!:15615:0:99999:7:::
root@linuxnix.com:/home/surendra#

if you see !(negation or exclamation) in second field of ‘kumar’ username in /etc/shadow file, it indicates user password is not set.

Step 2 : Create password for an user

passwd username

Example command:

root@linuxnix.com:/home/surendra# passwd krishan
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully

This command will ask for the conformation for the password and will not show what you type. Just retype the password. Once the password is matched it gives information that password updated successfully.

Now try to login with the username and password and enjoy Linux login access.

Advanced way of creating password in Linux

We can even create password by using md5pass command to create a password checksum and keep this encrypted password in shadow file.

Step1: Create encrypted password using md5pass as shown below.

md5pass redhat

Example:

root@linuxnix.com:/home/surendra# md5pass krishan
$1$At.eFgfG$BxrbG/v8qZTZoEb7SRJpw.
root@linuxnix.com:/home/surendra#

Step2: Now copy the encrypted password ‘$1$At.eFgfG$BxrbG/v8qZTZoEb7SRJpw.’ without quotes  to the second field of user ‘kumar’ entry in /etc/shadow file.

vi /etc/shadow

enter the password in second field of username:kumar and save the file.

Step 3 : Check if the password is updated or not

grep kumar /etc/shadow

Example output:

root@linuxnix.com:/home/surendra# grep kumar /etc/shadow
kumar:$1$At.eFgfG$BxrbG/v8qZTZoEb7SRJpw.:15615:0:99999:7:::
root@linuxnix.com:/home/surendra#

Now try to login with the username and password what you created now.

Note: This is just for knowledge purpose and do not try on production machines.

The following two tabs change content below.
Mr Surendra Anne is from Vijayawada, Andhra Pradesh, India. He is a Linux/Open source supporter who believes in Hard work, A down to earth person, Likes to share knowledge with others, Loves dogs, Likes photography. He works as Devops Engineer with Taggle systems, an IOT automatic water metering company, Sydney . You can contact him at surendra (@) linuxnix dot com.