Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversHalloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
VGSources
Blog

How to Reset a Forgotten Sudo or Root Password on a Linux Server

A sudo prompt usually wants the invoking user's password, not root's. Follow the correct recovery path for Ubuntu, RHEL 9 or Debian, then verify access safely.
Length10 min Posted Quest giverVGSources Team
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A sudo prompt normally asks for the password of the account you are currently using, not the root password. If another administrator can still use sudo, reset the affected account with sudo passwd username. If no administrator can log in, you need an authorized recovery path: Ubuntu recovery mode, RHEL 9’s rd.break boot method, or trusted live-rescue media for Debian and similar systems.

First identify which password was forgotten

Linux systems commonly involve three different credentials: a user’s login password, the root account’s password, and the password entered when sudo asks for authorization. Confusing them leads to the wrong recovery procedure.

As an Amazon Associate I earn from qualifying purchases.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A sudo prompt usually validates your own password

The sudoers policy validates the invoking user’s credentials, not the target account’s credentials. When user alice runs sudo systemctl restart ssh, the prompt normally expects Alice’s password even though the command runs with root privileges. It does not normally expect the root password.

Therefore, forgetting the password for your regular account is an account-recovery problem. Forgetting a separately enabled root password is a root-account problem. A failed sudo prompt can also mean that the account is not authorized, is locked, or is using an unexpected authentication policy rather than simply having the wrong password.

Ubuntu’s default root-account model

Ubuntu disables direct administrative root login by default. The installer generally places the first user in the sudo group, and that account uses its own password for administration. A root password may still be set later, but it is not required for normal Ubuntu administration.

On Ubuntu, use sudo passwd username to change a user’s password when you have a working administrator account. To set a root password deliberately, an authorized administrator can run sudo passwd root. To lock the root password again, use sudo passwd -l root.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose the recovery path

Situation Best path Access required Important side effects
Another account can run sudo Run sudo passwd username from that account Normal SSH or console login Changes only the selected account’s password
Ubuntu has no usable administrator login GRUB Advanced options, recovery mode, root shell Local console or a provider console that exposes GRUB Requires remounting the root filesystem read-write
RHEL 9 has no wheel user with sudo GRUB edit with rd.break Console access and permission to edit the boot entry Requires SELinux relabeling after the reset
Debian or another distribution lacks a usable local recovery entry Trusted live-rescue media, mount, and chroot Physical or virtual-media console access You must mount the installed system, not the live environment
Full-disk encryption is enabled Use the normal recovery path after unlocking the encrypted volume Console plus the disk-unlock passphrase or key Without the unlock credential, password reset cannot reach the installed filesystem

Only use these procedures on systems you are authorized to administer. Boot editing, virtual-console access, and live-media access can allow anyone with that access to replace local credentials.

Reset a password when another sudo-capable account works

This is the shortest and least disruptive method. Log in as an administrator whose password is known and whose account is authorized for sudo.

  1. List local accounts if you need to confirm the exact login name: getent passwd. Ubuntu’s local account database is represented in /etc/passwd; do not rely on a display name or an abbreviated username.
  2. Reset the affected user’s password: sudo passwd username. Replace username with the exact account name.
  3. For a root password that was intentionally enabled, run sudo passwd root. The currently logged-in administrator’s password authenticates the sudo operation.
  4. When prompted, enter the new password twice. A successful run reports that the password was updated.
  5. Check that the target account still has the intended administrative group. On Ubuntu, inspect membership with id username and look for sudo; on RHEL, look for wheel.

Changing a user’s password does not automatically add that user to an administrative group. Conversely, adding broad privileges to solve a password problem can create a larger security issue. Preserve the existing authorization design unless you have a separate reason to change it.

If sudo says the user is not authorized

A correct password cannot compensate for missing sudo policy. Check the account’s groups and the policy files /etc/sudoers and /etc/sudoers.d/. Do not edit the main sudoers file with an ordinary text editor; if a policy change is required, use visudo so syntax is checked before the file is installed.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

On RHEL, the normal administrative group is wheel. On Ubuntu, it is usually sudo. If the account is absent from the appropriate group, an existing administrator can add it with the distribution’s group-management command, then start a new login session before testing again.

Ubuntu: use recovery mode when no administrator can log in

Ubuntu’s documented recovery route gives you a root shell outside the normal login process. It is intended for a local machine or a virtual machine whose console exposes the bootloader. Many hosted servers hide GRUB behind a provider interface, so the exact screens and keystrokes vary.

Open the recovery shell

  1. Reboot the server and open the GRUB menu. On many systems, holding Shift during BIOS startup or pressing Esc during UEFI startup reveals it; a hosted console may provide its own control for showing the menu.
  2. Choose Advanced options for Ubuntu.
  3. Select the appropriate Ubuntu kernel entry ending in (recovery mode). If several kernels are listed, choose the kernel you normally boot unless you are troubleshooting a kernel-specific failure.
  4. In the recovery menu, choose root – Drop to root shell prompt.
  5. If the shell reports that the installed root filesystem is read-only, remount it read-write: mount -o remount,rw /.

Change the account password

At the root prompt, reset a regular user with:

passwd username

To set a root password specifically, use:

passwd root

Enter the new password twice. If the command reports that the password was updated, leave the shell with exit and choose the menu option to resume normal boot, or reboot from the shell with reboot after any pending recovery operation has finished.

Recovery mode acts on the installed Ubuntu filesystem. It does not require you to know the old password, but it does require access to the machine’s console and, when applicable, the disk-encryption passphrase.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

When an Ubuntu hosted server does not show GRUB

A cloud or virtual-server provider may expose only a serial console, a web console, or a rescue image. If GRUB is inaccessible, use the provider’s documented console or rescue workflow rather than assuming that the desktop recovery instructions apply. If the provider offers an out-of-band reset, confirm that it changes the installed instance’s account and not a temporary rescue environment.

RHEL 9: reset with the rd.break boot method

Red Hat Enterprise Linux 9 documents a special boot path for the case in which root login is unavailable and no non-root user has sudo permission. It pauses the boot process before the installed system is fully started, allowing you to change the password from a root shell.

Enter the emergency shell

  1. Reboot and stop at the GRUB menu. Select the RHEL kernel you intend to boot.
  2. Press e to edit the boot entry.
  3. Find the line beginning with linux (on some systems it may wrap onto a second screen).
  4. Move to the end of that line, add a space followed by rd.break, and press Ctrl+x to boot with the temporary option.
  5. At the break prompt, remount the installed system read-write: mount -o remount,rw /sysroot.
  6. Change the apparent root directory to the installed system: chroot /sysroot.

Set the password and prepare SELinux relabeling

For the root account, run:

passwd

For a regular account, specify its name:

passwd username

Create the relabel marker required by the RHEL procedure:

touch /.autorelabel

Leave the chroot with exit, then leave the break shell with a second exit. The system will continue booting, or you can follow the console’s reboot prompt. On the next boot, SELinux relabeling runs across the filesystem. The first startup can take considerably longer than usual; do not interrupt it merely because the login prompt is delayed.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The rd.break option is a temporary boot argument. It is not a setting that should remain in the bootloader configuration after recovery.

Debian and similar systems: use trusted live-rescue media

When the installed system has no usable recovery entry, boot a trusted Debian live image or another rescue environment that matches the machine’s architecture. Physical media, a virtual ISO, or a provider rescue image can work, provided you control its provenance and can access the server console.

Mount the installed root filesystem

  1. Boot the rescue environment and open a root shell. A live environment may provide a terminal where you can become root with its documented method.
  2. Identify the installed root partition with lsblk -f. Confirm the filesystem, labels, and sizes before mounting anything.
  3. Create a mount point and mount the installed root filesystem, for example: mkdir -p /mnt followed by mount /dev/your-root-partition /mnt. Replace the device name with the actual root partition; do not copy the example literally.
  4. If the installation uses separate /boot, /usr, or other filesystems, mount them beneath /mnt at their installed paths before chrooting.
  5. Enter the installed system: chroot /mnt /bin/bash.

Reset the installed account

From the chroot, run:

passwd username

To change root’s password, use passwd root. The command must run after the installed root filesystem is mounted and the chroot is active. Running passwd in the live environment without the chroot changes the rescue system’s accounts, not the server you are repairing.

When finished, leave the chroot with exit, unmount the installed filesystems cleanly, remove the rescue media, and reboot into the installed system. If the machine uses software RAID, LVM, or encryption, activate and mount those layers according to the installation’s layout before attempting the chroot; an incomplete mount can make the command appear to succeed while modifying the wrong environment.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Verify the reset without creating a new access problem

  1. Start a fresh login session. Existing SSH sessions may retain cached credentials or an existing sudo timestamp and therefore do not prove that the new password works.
  2. Test the account’s normal login method, such as the console or SSH path used by that account. Use the exact username you reset.
  3. For an administrative user, run a harmless check such as sudo whoami. A successful result should be root. Do not use a destructive command merely to test elevation.
  4. Confirm authorization with id username. Check for the intended sudo group on Ubuntu or wheel on RHEL rather than granting unrestricted access to compensate for a missing group.
  5. If sudo still reports that the user is not permitted, inspect /etc/sudoers and /etc/sudoers.d/ for the policy that should authorize the account. Validate any policy edit with visudo.
  6. On RHEL, wait for the SELinux relabel operation to complete and then test again. A delayed first boot is expected after creating /.autorelabel.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Common failure modes and their fixes

“I used the root password at the sudo prompt, and it failed”

That is expected on a normal sudo configuration because sudo asks for the invoking user’s password. Log in as that user and reset its password from another administrator, or use the appropriate offline recovery path.

“The recovery shell says the filesystem is read-only”

Password databases cannot be updated on a read-only root filesystem. In Ubuntu recovery mode, run mount -o remount,rw /. In the RHEL 9 break environment, remount /sysroot with mount -o remount,rw /sysroot before chrooting.

“The reset worked, but sudo still says I am not allowed”

Password authentication and sudo authorization are separate checks. Verify group membership and the applicable policy files. A password reset does not add the account to sudo or wheel.

“The live-media reset changed nothing”

You probably changed the rescue environment instead of the installed system, or mounted the wrong partition. Recheck lsblk -f, mount the actual root filesystem at /mnt, and run passwd only after entering the chroot.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

“The server will not show GRUB”

Hosted platforms often suppress the boot menu. Use the provider’s serial or virtual console, attach approved rescue media, or request an authorized out-of-band recovery. Do not assume that an SSH-only interface can perform an offline password reset.

“RHEL takes a long time to boot after the reset”

The /.autorelabel marker causes SELinux to relabel files. Allow that operation to finish before declaring the recovery unsuccessful. Interrupting it can leave contexts incomplete and create additional startup problems.

Security implications and prevention

Anyone who can edit a boot entry, access a provider console, attach a rescue image, or remove a server’s storage can often replace local passwords. Treat those capabilities as equivalent to administrator access.

  • Protect physical access, GRUB editing, and out-of-band management consoles with strong authentication and restricted operator permissions.
  • Use full-disk encryption where its operational model fits the server, and store the unlock key separately from the machine. Encryption protects data at rest, but it does not remove the need to secure an already-unlocked console.
  • Keep at least one tested, authorized administrative account and document its recovery route. Test the route during maintenance rather than during an outage.
  • Store credentials in an approved password manager and maintain a controlled break-glass process.
  • Do not edit /etc/shadow manually when passwd is available. The command applies the correct hashing and account-file updates for the distribution.
  • Avoid permanently enabling direct root login unless a documented security policy requires it. On Ubuntu, restore the default locked state with sudo passwd -l root after any temporary root-password operation.
  • If the reset follows a suspected compromise, preserve authentication logs, console records, and incident details before rotating additional credentials or rebuilding the host.

The safest procedure is the narrowest one that restores the intended account: use a working sudo administrator when available, an offline root shell only when necessary, and verify both authentication and authorization before returning the server to service.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More quests from Patch Notes

  1. How to Set Up a RedM (RDR2) Server in 2026: License Key, txAdmin and server.cfg, Step by StepBlog11min
  2. Best RedM (RDR2) Server Hosting in 2026: Comparing Four Hosts on Slots, Memory and PriceBlog10min
  3. How to Host a Mindustry Server in 2026: server-release.jar, Port 6567 and the Commands That MatterBlog7min
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.