How to Reset the Root Password on an Ubuntu VPS

  • Home
  • Blog
  • How to Reset the Root Password on an Ubuntu VPS
RDPextra
DateOct 29, 2024

Root password recovery is relevant to Ubuntu VPS and dedicated servers running Ubuntu. The recovery process depends on the server’s operating system and the level of access available to the user. With console access, users can access the GRUB boot menu, enter recovery mode, and reset the root password using the appropriate commands. The exact steps may vary depending on the server configuration. Windows RDP servers use a different administrator password recovery method, so the Ubuntu GRUB procedure described in this guide does not apply to them.

Ubuntu VPS password reset guide

Need an Ubuntu server? See our Linux VPS plans.

Common Situations Requiring a Root
Password Reset.

You may need to reset the root password on an Ubuntu server in several situations:

  • Forgotten Password: An administrator may forget the root password, especially if it has not been used for a long time.
  • Security Requirements: You may need to change the root password to meet your organization’s security policies or after a suspected security incident.
  • SSH Access Problems: Issues with SSH keys or permissions may prevent you from accessing your server. A password reset may help if you have access to the server console.
  • New Ownership or Server Transfer: When transferring an Ubuntu server to a new owner, update the root password and review existing user access to help secure the system.
  • Failed System Updates: An interrupted system update may cause authentication or access problems. In some cases, you may need to recover access and reset the root password.

Why Root Access Is Important on an Ubuntu Server

Ubuntu server console with GRUB recovery menu

Before resetting the root password, it is helpful to understand why root access is important on an Ubuntu server.

  1. VPS (Virtual Private Server): An Ubuntu VPS provides a virtual server environment where users with root privileges can manage system settings, install software, and perform administrative tasks. Root access can also be useful when troubleshooting system issues or recovering account access.
  2. Dedicated Servers Running Ubuntu: Ubuntu dedicated servers provide access to dedicated hardware and the operating system. Users with root privileges can manage system configurations, install packages, and perform administrative tasks. Available access depends on the hosting provider and server configuration.

Understanding the recovery process can help you regain access when you cannot log in normally. Always use a recovery method supported by your server configuration and keep your login credentials secure.

Key Tools Required to Reset the Root Password

Before resetting the root password on an Ubuntu server, make sure you have access to the following:

  1. Console or VNC Access: Your hosting provider may offer console or VNC access through its control panel. This lets you interact with the server even when SSH login is unavailable.
  2. GRUB Bootloader: Ubuntu uses GRUB to start the operating system. If your server allows access to the GRUB menu, you may be able to use its boot options to open a root recovery shell.
  3. SSH Access (After Recovery): You can use SSH to reconnect to your Ubuntu server after recovery, provided that SSH access and the required login method are enabled.

Step-by-Step: How to Reset the Root Password

Step 1: Reboot the VPS or Dedicated Server

  1. Log in to your hosting provider’s control panel.
  2. Locate the reboot or restart option and restart your Ubuntu server.
  3. If you need to access the GRUB menu, open the provider’s console or VNC session during startup.

The exact process depends on your hosting provider and server configuration.

Step 2: Access the GRUB Menu

  1. As the server restarts, press Esc or Shift to open the GRUB menu. The correct key depends on your system configuration.
  2. Use the server console to monitor the boot process.
  3. If the menu does not appear, restart the server and try pressing the Esc key earlier during startup.

Step 3: Modify GRUB Boot Parameters

Ubuntu Version and Recovery Compatibility: These instructions are intended for Ubuntu servers that provide access to the GRUB boot menu and a root recovery shell. GRUB behavior may vary across Ubuntu versions, cloud platforms, and hosting providers. Check your provider’s documentation before proceeding.

  1. Select the Ubuntu boot entry in the GRUB menu and press e to edit it.
  2. Find the line that starts with linux.
  3. Add the following parameters at the end of that line:
rw init=/bin/bash

Press Ctrl + X to boot the system into a root shell.
Once the root shell opens, run the following command to ensure that the root filesystem is mounted in read-write mode:
mount -o remount,rw /

Wait for the command to complete before proceeding to Step 4.

Alternative: Use Your Hosting Provider’s Rescue Mode

If you cannot access the GRUB menu or open a root shell, check whether your hosting provider offers Rescue Mode or a Recovery Environment.

Follow the provider’s instructions to access the server’s filesystem and reset the appropriate account password. Available recovery options vary by provider and server configuration. Back up important data before making recovery changes whenever possible.

Step 4: Reset the Root Password

  1. Once the root shell is available and the filesystem is writable, run:

                                       passwd root
  1. Enter the new password when prompted, then enter it again to confirm.
  2. If the password is changed successfully, Ubuntu will display a confirmation message.

Note: On Ubuntu, the root account is commonly locked by default. Administrators normally use a regular account with sudo privileges. If you only need to reset your regular administrator account password, use passwd username instead of passwd root, replacing username with the actual account name. Only set a root password if you specifically need root account login.

Step 5: Restore the System to Normal Boot

  1. After resetting the password, flush pending filesystem writes by running:
                                         sync
  1. Restart the server using your hosting provider’s control panel or console. If a console-based forced restart is required, you can run:
reboot -f

A forced restart may bypass the normal shutdown process, so use it only when the server is running in the recovery shell and the password reset is complete.

  1. Wait for Ubuntu to start normally before attempting to log in again.

Verify the Reset Password

After resetting the password, verify that you can access your Ubuntu server using the appropriate login method.

  1. SSH Access: If root SSH login is enabled, open an SSH client and connect using:
                                     ssh root@your-server-ip
  1. Replace your-server-ip with your server’s actual IP address.
  2. If root SSH login is disabled, use your configured administrative account or the server console to verify access.

Troubleshooting Common Password Reset Issues

GRUB Not Loading Properly

  • Make sure you press the Shift or Esc key at the correct time during the boot process.
  • On dedicated servers, check your hosting provider’s documentation for instructions on accessing the GRUB menu.

SSH Still Inaccessible.

  1. Check whether the SSH service is running. You can restart it using the following command:

                                           sudo systemctl restart ssh
  1. Check your server’s firewall rules to make sure SSH traffic is allowed. Also, confirm that the SSH service is configured correctly and that the required port is open.

Enhancing Security After a Password Reset.

Resetting the root password on an Ubuntu VPS

Resetting the root password is only the first step. Follow these best practices to improve your server’s security:

  1. Disable Root Login Through SSH

Open the SSH configuration file:

          

          sudo nano /etc/ssh/sshd_config

Set the PermitRootLogin option to no and restart the SSH service:


                            sudo systemctl restart ssh

Important: Before disabling root login, make sure you have another user account with sudo privileges. Otherwise, you may lose administrative access to your server.

2. Use SSH Keys for Authentication

    SSH keys provide a more secure alternative to password-based authentication. They help protect SSH access by using a key pair instead of relying only on a password.

                                            

    3. Install and Configure a Firewall

      Use UFW (Uncomplicated Firewall) to manage network traffic and block unauthorized access. Make sure the required SSH connection is allowed before enabling the firewall.

      4. Monitor Server Logs

      Monitor server logs regularly to identify unusual login activity. You can also install tools such as Fail2ban to detect suspicious login attempts and block repeated unauthorized access.

      When to Consider Additional Server Resources

      If your Ubuntu VPS regularly struggles with demanding workloads, you may need additional server resources. Review your CPU, RAM, and storage usage to identify possible limitations. Depending on your requirements, upgrading your VPS plan or choosing a server with more resources may improve performance. Make sure you have the required administrative access before making system-level changes.

      You can also learn how to check system resources in Ubuntu before upgrading your server resources.

      Choosing the Right Hosting Provider.

      When selecting a hosting provider for an Ubuntu VPS or dedicated server, consider the following factors:

      • Recovery Console Access: Choose a provider that offers console access so you can access the server if SSH login becomes unavailable.
      • Technical Support: Check whether the provider offers support for boot issues, recovery mode, and server access problems.
      • Operating System Support: Confirm that the provider supports your Ubuntu version and provides the necessary recovery options.
      • Backup Options: Look for backup facilities that can help protect your data before making major system changes.

      Conclusion

      Knowing how to reset the root password on an Ubuntu VPS helps you keep control of your server. If you lose access, boot into the GRUB recovery shell, set a new password, and then secure the server again with SSH keys, a firewall and Fail2ban.

      Keep console or rescue-mode access with your provider, take regular backups, and use a regular account with sudo for daily work. If you need a new Ubuntu server, see our Linux VPS plans.

      Author avatar
      Evan Allenn

      Evan Allenn writes technical guides and troubleshooting articles at RDPextra. He has 3 years of experience in the hosting industry and focuses on clear, step-by-step instructions for RDP, VPS and server users.

      0 0 votes
      Article Rating
      Subscribe
      Notify of
      guest
      0 Comments
      Oldest
      Newest Most Voted
      0
      Would love your thoughts, please comment.x
      ()
      x