Skip to main content

Linux Security

How to Change the Password on a Linux Server

Learn how to change passwords on a Linux server for better security. Follow these simple steps for updating your credentials or managing user accounts, including tips for administrators and enforcing strong password policies.
 |  XooNET  |  The Web
How to change the password in a linux server or machine

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:

 

  1. Run the command: passwd
  2. Enter your current password when prompted.
  3. 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:

  1. Run the command with the target username:
    sudo passwd username
  2. Enter your own password if prompted.
  3. 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:
    PasswordAuthentication no
    Restart the SSH service:
    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.