How to Change the Password on a Linux Server

Changing the password on a Linux server is an essential skill for maintaining security and managing user accounts. This guide will walk you through the process, whether you're an administrator or an individual user.
Step 1: Log in to the Linux Server
To change your password, you'll need access to the server. Use SSH (Secure Shell) to log in if you're working remotely:
ssh username@server_ip
Replace username
with your actual username and server_ip
with the server's IP address or hostname.
Step 2: Change Your Password
Once logged in, you can update your password using the
passwd
command:
- Run the command:
passwd
- Enter your current password when prompted.
- Type your new password and confirm it. Use a strong password with a mix of uppercase, lowercase, numbers, and special characters.
If the password update is successful, you'll see this message:
passwd: password updated successfully
Step 3: Change Another User's Password (Administrator)
If you’re an administrator and need to update another user’s password:
- Run the command with the target username:
sudo passwd username
- Enter your own password if prompted.
- Input the new password for the user and confirm it.
Step 4: Ensure Secure Access
For added security, consider the following steps:
- Enforce Strong Password Policies: Use
pam_pwquality
to enforce password complexity. Edit/etc/security/pwquality.conf
to define rules. - Disable Password Authentication for SSH: Use SSH key-based authentication. Edit
/etc/ssh/sshd_config
to disable password-based logins:
Restart the SSH service:PasswordAuthentication no
sudo systemctl restart sshd
Troubleshooting
- Permission Denied: Ensure you have sufficient privileges. Use
sudo
if necessary. - Password Policy Violation: Choose a more complex password if the new password doesn’t meet system policies.
Conclusion
Changing a password on a Linux server is straightforward with the passwd
command. Regular updates and adhering to security best practices will help maintain a secure server environment.