Setting a Password for the New User
Every user account should have a secure password to prevent unauthorized access. In this step, you will set a password for the "cipher" user you created in the previous step.
- Use the
passwd
command to set a password for the user:
sudo passwd cipher
- You will be prompted to enter a new password twice. Type a password of your choice and press Enter after each entry. Note that for security reasons, the password you type will not be displayed on the screen.
New password:
Retype new password:
If both passwords match, you'll see a confirmation message:
passwd: password updated successfully
- Verify that the password has been set by checking if the password field in the shadow file is no longer empty:
sudo grep cipher /etc/shadow | cut -d: -f2 | grep -v '!'
If a string of characters is returned, it means the password has been set successfully. The output won't show the actual password but rather its encrypted form.
Let's understand the verification command in detail:
grep cipher /etc/shadow
finds the line containing our user
cut -d: -f2
extracts the password field (second field)
grep -v '!'
shows only lines that don't contain '!'
The last part (grep -v '!'
) is particularly important because in Linux:
- An account with no password or a locked account will have '!' in the password field
- An account with a valid password will have an encrypted hash without '!'
Therefore, if the command returns output, it confirms that a valid password is set without exposing the actual password hash.