That's a very common real-world scenario! In Linux, because passwords are hashed (one-way), they cannot be "recovered" or "decrypted." Instead, a user with administrative privileges must reset it.
Here is how it is handled:
1. Resetting via an Administrator
If a regular user forgets their password, they must ask a user with sudo privileges (like yourself in this lab) to change it for them. As an administrator, you simply run the same command you just learned:
sudo passwd username
You won't be asked for the user's old password; you just set a new one immediately.
2. Force Password Change on Next Login
To be extra secure, after an administrator resets a password, they often force the user to change it to something private the next time they log in. You can do this with the chage command:
sudo chage -d 0 username
3. What if the Root/Admin forgets their password?
If the only administrator on the system forgets their password, it's a bit more complex. One would typically need to:
- Physical/Console access to the machine.
- Reboot the system into "Single User Mode" or a "Recovery Mode" from the boot menu (GRUB).
- From there, the system drops into a root shell without asking for a password, allowing the admin to run
passwdto fix the account.
In this lab, as long as you are logged in as the labex user, you have the power to reset joker’s password whenever you like!