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.
Latest posts by Surendra Anne (see all)
- Docker: How to copy files to/from docker container - June 30, 2020
- Anisble: ERROR! unexpected parameter type in action:
Fix - June 29, 2020 - FREE: JOIN OUR DEVOPS TELEGRAM GROUPS - August 2, 2019
- Review: Whizlabs Practice Tests for AWS Certified Solutions Architect Professional (CSAP) - August 27, 2018
- How to use ohai/chef-shell to get node attributes - July 19, 2018