LowEndBox - Cheap VPS, Hosting and Dedicated Server Deals

Resetting that Linux Root Password You Forgot

lowendtutorial

You had to type it twice. You were supposed to put it in your password safe. You were going to setup sudo but didn’t get a chance. You know it’s something to do with a Scooby Doo cartoon and that one blues band you like but now you just can’t remember your Linux root password.

Fear not, intrepid admin, there are ways to recover it. In this tutorial we’ll walk you through recovering your root password on Linux.

The Easy Ways

If you have an account that can su to a shell, you can easily run “passwd root” and reset it. Problem solved.

Depending on the virtualization and panel, you may be able to reset it from inside your provider’s panel. This is universal with OpenVZ and some of the larger players (Vultr, Dropbox, Linode, etc.)

If these aren’t options for you, we’ll do it the old fashioned way.

The Less Easy Way

You’ll need to mount a CD and reboot. In times past you had to use a rescue CD (or boot your installation media in rescue mode) but we’ll show you how to do this via grub.

I’m using a VPS at BuyVM, so the screenshots here will be for the Stallion panel, but they’re very similar for Solus, etc.

I’ve reinstalled a clean copy of Debian 10 on a VPS named oops.lowend.party. I’ll boot it and then login. Now I’ll reset it to something quite random:

root@localhost:~# echo $RANDOM$RANDOM$RANDOM$RANDOM
271201341711691335
root@localhost:~# passwd root
New password: (copied and pasted from above)
Retype new password: 
passwd: password updated successfully
root@localhost:~#

I didn’t write the random string down so I have no idea what the password is.

Next I mounted the Debian 10 x64 CD. Then I changed the boot order so that CDs boot first:

Now I will launch the console and then reboot.

When the GRUB bootloader appears, hit the down arrow to move on to “Advanced options for Debian GNU/Linux”, then hit Enter.

Now press ‘e’ for edit. You need to make two changes highlighted below on the line that begins with “linux /boot/vmlinuz…”. You can use your arrow keys to move the cursor.

(1) change the ‘ro’ parameter to ‘rw’
(2) add init=/bin/bash at the end

Then hit control-X to save and boot.

Linux will boot and you will come to a shell prompt. Enter the following command to mount your root filesystem:

mount -n -o remount,rw /

Then set the root password:

passwd root

Note: You may see a lot of “visual noise” – log messages that suddenly appear on the screen. Ignore these because they are not being interpreted in what you type.

Once you’re done, type the following to reboot

exec /sbin/init

Then upon reboot, I was able to login with the new root password I’d set.

 

raindog308

No Comments

    Leave a Reply

    Some notes on commenting on LowEndBox:

    • Do not use LowEndBox for support issues. Go to your hosting provider and issue a ticket there. Coming here saying "my VPS is down, what do I do?!" will only have your comments removed.
    • Akismet is used for spam detection. Some comments may be held temporarily for manual approval.
    • Use <pre>...</pre> to quote the output from your terminal/console, or consider using a pastebin service.

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