Gaming industry under DDoS attack. Get DDoS protection now. Start onboarding
  1. Home
  2. Developers
  3. How to Reset Password in Linux

How to Reset Password in Linux

  • By Gcore
  • August 30, 2023
  • 3 min read
How to Reset Password in Linux

Forgetting a password can be a minor hiccup for most, but when it comes to Linux—a system known for its robust security features—it can feel like a daunting obstacle. Whether you’re new to the world of open-source operating systems or a seasoned Linux veteran, resetting your password doesn’t have to be a complex chore. This guide offers a concise, step-by-step approach to help you swiftly regain access to your Linux machine.

Resetting Linux Password using GRUB

Resetting a Linux password using the GRUB bootloader involves booting into single-user mode or recovery mode and then using the command line to reset the password. Here’s a step-by-step guide:

1. Access the GRUB menu. GRUB (Grand Unified Bootloader) is the default bootloader for most Linux distributions. First, restart or power on your computer.  As soon as the boot process begins, press and hold the Shift key (for some systems it might be the Esc key) to bring up the GRUB menu.

2. Enter the Edit Mode. Before booting into the system, you need to edit the boot parameters. First, highlight the default boot entry (usually the first in the list) using arrow keys. 

  • Press ‘E’ to edit the entry.

3. Modify Boot Parameters. To boot into single-user mode, you need to modify the Linux boot parameters. Here are the following steps:

• Find the line that starts with linux or linux16. This line specifies the boot parameters.
• At this line, locate ‘ro quiet’, replace ‘ro’ to ‘rw’ then add the word single or init=/bin/bash, depending on your distribution and setup.
• Press Ctrl + X or F10 to boot with the modified parameters.

Here’s an example:

4. Remount the File System with Write Permissions. By default, the filesystem might be in read-only mode in this state. To change the password, you’ll need write permissions. Enter the following command:

mount -n -o remount,rw /

5. Reset the Password. Use the passwd command to reset the password for a user. Enter the command below, replacing ‘username’ with the actual username for which you want to reset the password:

passwd username

When prompted, enter the new password twice.

6. Reboot the System. Now that the password is reset, it’s best to reboot the system to return to normal operation. Enter the following command:

sync

Then, force a reboot with:

reboot -f

The new password should now be active, and you can test it. In the following section, we’ll explore an alternative method using a live CD or USB.

Resetting Linux Password Using Live CD/USB

Resetting a Linux password using a Live CD or USB is a useful method when you’ve forgotten the root or user password. Here are the step-by-step instructions:

1. Boot from the Live CD/USB. Insert your Live CD or USB stick. Reboot the computer and choose to boot from the CD/USB from the BIOS or UEFI boot menu.

2. Open a Terminal. Once the live environment is loaded, locate and open a terminal window.

3. Identify the System’s Root Partition. You can use tools like fdisk or lsblk to identify your system’s root partition.

sudo fdisk -l# orsudo lsblk -f

Look for partitions that are likely Linux root partitions, such as ext4, xfs, etc.

4. Mount the Root Partition. Create a mount point by running this command:

sudo mkdir /mnt/myroot

Mount the identified root partition (replace /dev/sdXY with your partition, for example, /dev/sda1):

sudo mount /dev/sdXY /mnt/myroot

5. Change Root into the System. Use chroot to change the root directory by using this command:

sudo chroot /mnt/myroot

6. Reset the Password. Now that you’ve chrooted into your system, you can use the passwd command to change the password for any user, including root.

passwd username

Replace “username” with the actual username or use root to reset the root password.

7. Exit and Unmount. Exit the chroot environment and unmount the partition.

exitsudo umount /mnt/myroot

8. Reboot. Remove the Live CD/USB and reboot your computer. Now, you should now be able to log in using the new password.

That’s it! You’re now able to reset passwords in Linux. To reset passwords, you can use either the GRUB method or a Live CD. The GRUB method is fast and doesn’t need external tools, but a Live CD is more universal and works well for complex system setups or restricted GRUB access.

Conclusion

Looking to deploy Linux in the cloud? With Gcore Cloud, you can choose from Basic VM, Virtual Instances, or VPS/VDS suitable for Linux:

Choose an instance

Related articles

What is an IXP?

When you send an email or stream a video, your data doesn't just magically hop from your computer to its destination. It travels through multiple networks, and somewhere along that path, it might passes through an Internet Exchange Point (I

What is global server load balancing (GSLB)?

Global server load balancing is a traffic management system that distributes user requests across servers in multiple geographic locations to improve performance and reliability. This approach can reduce latency by 40-60% compared to single

Edge Functions: How They Work, Benefits, and Use Cases

When you're building a web application, there's a good chance you've faced this problem: your server sits in one location, but your users are scattered across the globe. That means someone in Tokyo waits longer for a response than someone i

What Is CDN SSL? How It Works, Benefits, and Setup

Most websites today use HTTPS. In fact, 68% of the top million websites have made the switch. But if you're using a CDN to speed up content delivery, SSL/TLS encryption works differently than you might expect. Your origin server isn't handl

What Is Health Check Monitoring? Benefits and Best Practices

Health check monitoring is a systematic process that tracks the availability and performance of your servers, applications, and infrastructure by sending automated requests at regular intervals. Most systems run checks every 30 to 60 second

What is GSLB and why is it important for global applications?

GSLB (Global Server Load Balancing) is a load balancing service that distributes client requests across multiple geographically dispersed data centers to improve performance, availability, and compliance.At its core, GSLB works at the DNS l

Subscribe to our newsletter

Get the latest industry trends, exclusive insights, and Gcore updates delivered straight to your inbox.