Introduction
In this lab, we will explore the Linux passwd command, which is used to change user passwords. We will learn how to check the current user's password status, change the password for a specific user account, and reset the password for a user account when the user has forgotten their password. The passwd command is a fundamental tool for managing user accounts and security in a Linux system.
The lab covers the following steps:
- Understanding the
passwdcommand - Changing user password
- Resetting forgotten password
Understanding the passwd Command
In this step, we will explore the Linux passwd command, which is used to change user passwords. The passwd command is a fundamental tool for managing user accounts and security in a Linux system.
First, let's check the current user's password status:
passwd -S labex
Example output:
labex PS 2023-04-12 0 0 99999 7 -1 (Password set, SHA512 crypt.)
This output shows that the labex user has a password set, and the password is encrypted using the SHA512 algorithm.
Now, let's change the password for the labex user:
sudo passwd labex
You will be prompted to enter the new password twice:
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
The passwd command updates the user's password in the /etc/shadow file, which stores the encrypted passwords for all user accounts on the system.
Changing User Password
In this step, we will learn how to change the password for a specific user account in the Linux system.
First, let's create a new user account named newuser:
sudo useradd -m newuser
Now, let's change the password for the newuser account:
sudo passwd newuser
You will be prompted to enter the new password twice:
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
The passwd command updates the user's password in the /etc/shadow file, which stores the encrypted passwords for all user accounts on the system.
To verify the password change, you can switch to the newuser account and try to log in:
su - newuser
You should be able to log in with the new password you just set.
Resetting Forgotten Password
In this step, we will learn how to reset the password for a user account when the user has forgotten their password.
First, let's create another user account named forgottenuser:
sudo useradd -m forgottenuser
Now, let's try to reset the password for the forgottenuser account:
sudo passwd forgottenuser
You will be prompted to enter the new password twice:
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
The passwd command updates the user's password in the /etc/shadow file, which stores the encrypted passwords for all user accounts on the system.
To verify the password reset, you can switch to the forgottenuser account and try to log in:
su - forgottenuser
You should be able to log in with the new password you just set.
Summary
In this lab, we learned how to use the Linux passwd command to manage user passwords. We started by understanding the passwd command and checking the current user's password status. Then, we learned how to change the password for a specific user account, and finally, we explored the process of resetting a forgotten password. The lab provided practical examples and step-by-step instructions, ensuring a comprehensive understanding of password management in a Linux system.



