Passwords are essential for securing Linux systems. This guide shows you how to change passwords in Linux, both for your own user account and for other users on your VPS. Whether you're updating a compromised password or performing routine security maintenance, the process is straightforward using the passwd command.
Background
Linux manages passwords through two key system files. The /etc/passwd file contains information about all users and their system group affiliations. The /etc/shadow file stores users' encrypted passwords and SSH key information. You can view these files using:
cat /etc/passwd
cat /etc/shadow
Using strong passwords and changing them regularly is recommended to enhance security and prevent unauthorized access.
How to do it
-
Step 1: Access your system via SSH
Connect to your VPS through SSH as a regular user or root user, depending on whose password you want to change.
-
Step 2: Change your own password
To change the password for the currently logged-in user (including root), open the terminal and execute:
sudo passwdYou'll be prompted to enter the new password twice for confirmation. Note that you can change the root password without specifying the user during this process.
-
Step 3: Change another user's password
To change the password for a different user on the system, ensure you are logged in as root. Add the username to the
passwdcommand:passwd user_nameFor example, to change the password for a user named John:
passwd johnYou'll receive prompts to enter the new password twice.
-
Step 4: Verify the password change
After entering the new password twice, the system will confirm that the password has been updated successfully. The user can now log in with the new password.