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.
Related Posts:
- One Week From Tomorrow…THE WORLD WILL LOSE THEIR MINDS!Lines Are Already Forming! - November 21, 2024
- Crunchbits Discontinuing Popular Annual Plans – The Community Mourns! - November 20, 2024
- RackNerd’s Black Friday 2024: Bigger, Better, and Now in Dublin! - November 19, 2024
Leave a Reply