Did you forget the root password for your server? Not to worry, if you have local access to your server and your system is using GRUB as a bootloader you can follow our tutorial. This method works on most Linux operating systems but not limited to: Ubuntu, CentOS, and Debian. We have also included a method for FreeBSD and our rescue system GRML.

Contents
1. Change your password
2. Linux
3. Rescue Mode (GRML)
4. FreeBSD

Change your password

But what do you if you already have access to your system and just want to change your password? Make sure you are the root user or the user that you wish to change the password for and type this command in the shell:

[root@worldstream ~]# passwd

You will be prompted twice to enter a new password. After confirmation the password is set! We would recommend to use strong password generator to make up the password.

Linux

If you have forgotten the root password you can reset it if you have access to our out-of-band-management remote access VPN. Once you have started the video redirection follow these steps:

Perform a graceful reboot on the server with CTRL+ALT+DEL (most out-of-band-managements have a hot-key to perform this). Once the GRUB screen (boot screen) is shown press e to edit the boot options. If you notice that the GRUB screen is not shown during the boot process hold down the shift button. Navigate to the line starting with linux (this line is called kernel in GRUB). Move your cursor to end of line and enter the following: 

[root@worldstream ~]# init=/bin/bash

If your OS is a Red Hat distribution then use single instead of init=/bin/bash. Now press b or CTRL+X to boot the OS in single user mode. (you can press enter in earlier versions of GRUB). Once booted enter the following command:

[root@worldstream ~]# mount -o remount,rw /

This will mount the root partition in read/write mode. Now use this command to change the password:

[root@worldstream ~]# passwd

Now enter the password that you would like to change it too. To make sure that it writes to persistent storage use the below command. This is recommended with older systems.

[root@worldstream ~]# sync

Now perform a reboot again using CTRL+ALT+DEL or shutdown -r. If you have problems rebooting the server run the following commands:

[root@worldstream ~]# su root
[root@worldstream ~]# export PATH=$PATH:/sbin
[root@worldstream ~]# sudo reboot -f

Rescue mode (Grml)

If you have forgotten the root password and the above method did not work and you do not have a FreeBSD operating system either you can use Grml. This will boot your server in a safe environment. You can start this from our installation center from our panel. If you need any help starting the Grml installation you can use this article.

Once you have logged in via ssh we will create a folder to which we will chroot to.

[root@worldstream ~]# mkdir /mnt/recover

Then check what the correct root partition is with lsblk. In our example /dev/sda2 is our root partition. We will mount this to the created folder with this command:

[root@worldstream ~]# mount /dev/sda2 /mnt/recover

Once succeeded we will start a new shell inside our mounted partition.

[root@worldstream ~]# chroot /mnt/recover /bin/bash 

Now we can change the password with:

[root@worldstream ~]# passwd

Let’s issue the exit command and unmount the partition with:

[root@worldstream ~]# umount /mnt/recover

To make sure that it writes to persistent storage use the below command. This is recommended with older systems.

[root@worldstream ~]# sync

All we have to now is use the reboot command or a shutdown -r.

FreeBSD

If you have forgotten the root password you can reset it if you have access to our out-of-band-management remote access VPN. Once you have started the video redirection follow these steps:

Perform a graceful reboot on the server using CTRL+ALT+DEL. After loading the kernel select option 4 (or option 6 for FreeBSD 9). This will start the operating system in single user mode. Mount the filesystem with the following commands: 

[root@worldstream ~]# mount -u /
[root@worldstream ~]# mount -a

Now use this command to change the password:

[root@worldstream ~]# passwd

Now enter the password that you’d like to change it too and issue exit. This will boot the server to the login screen. The password is now changed!

If you have any questions or comments about this article about password resets feel free to email us here