How to Change the Root Password on a VPS CentOS 8

How to Change the Root Password on a VPS with CentOS 8

How to Change the Root Password on a VPS centOS 8 – Changing the root password on a VPS running CentOS 8 is a critical step for maintaining server security. Whether you’re setting up a new server or securing an existing one, this guide will walk you through the process in a straightforward manner.

Why Change the Root Password?

The root user has complete control over the server. To prevent unauthorized access, it’s essential to use a strong, unique password and change it regularly.

Prerequisites

Before you begin, ensure you have:

  • SSH access to your VPS.
  • The current root password or access to a user account with sudo privileges.

Step 1: Access Your VPS

  1. Open a terminal or SSH client (such as PuTTY for Windows or the terminal on macOS/Linux).
  2. Connect to your VPS using the following command:
    ssh root@your-server-ip
    

    Replace your-server-ip with your VPS’s IP address.

  3. Enter the current root password when prompted.

Step 2: Change the Password

Once logged in, follow these steps to change the root password:

  1. Run the following command to start the password update process:
    passwd
    
  2. You will be prompted to enter a new password. Make sure the password is strong, containing a mix of uppercase letters, lowercase letters, numbers, and symbols.
  3. Confirm the new password by typing it again.

If the password change is successful, you’ll see a confirmation message like:

passwd: all authentication tokens updated successfully.

Step 3: Verify the Password

To ensure the new password works:

  1. Log out of your VPS:
    logout
    
  2. Log back in using the new password:
    ssh root@your-server-ip
    

Alternative Method: Using a Sudo User

If you don’t have the root password but have access to a sudo-enabled user, you can reset the root password using the following commands:

  1. Log in with your sudo user credentials.
  2. Run the following command:
    sudo passwd root
    
  3. Enter the new root password and confirm it.

Additional Security Tips

  1. Disable Root Login via SSH: After changing the root password, consider disabling root login for enhanced security. This can be done by editing the SSH configuration file:
    nano /etc/ssh/sshd_config
    

    Look for the line PermitRootLogin and set it to no. Restart the SSH service to apply changes:

    systemctl restart sshd
    
  2. Use SSH Keys: For added security, configure SSH key-based authentication instead of relying solely on passwords.

Troubleshooting

If you encounter any issues:

  • Ensure your keyboard layout matches the one used when setting the password.
  • Double-check SSH settings if you cannot log back in.

Conclusion

Changing the root password on a CentOS 8 VPS is a straightforward yet vital task for securing your server. By following this guide, you can ensure that your server remains protected from unauthorized access. Always use strong passwords and implement additional security measures like disabling root login and using SSH keys for enhanced protection.

Avatar photo
Informasi Dunia Teknologi
adbanner