How to reset the root password on Linux and FreeBSD

Listed below are the step by step procedures to reset the root password in different versions of CentOS, CoreOS, Debian, Ubuntu and FreeBSD. Begin this procedure by booting your server into single user mode. If you have direct (physical access) to the server, then just reboot it and proceed with the steps for your OS below. In case that the server is in a datacenter and only accessible by remote console, begin with accessing customer portal of your server hosting provider and search for the KVM or server console. The rest of options are different and dependent on bootloader version in a machine.

CentOS 7, Ubuntu and Debian

Restart the server via any one of the two options. Choose [RESTART] button or click [View Console] and proceed further to click CTRL+ALT+DEL appearing on the top to the right. While booting, press ESC to open boot prompt.

GRUB boot prompt appears on screen, type e which opens the edit option for boot. (Upon absence of GRUB prompt, one can press any key before machine boot to open the prompt).

Type: "/bin/bash" (without the qoutes) at the end of line that has "linux/boot/" in the beginning.

Press F10 or CTRL-X to boot it again. Upon booting, the root prompt opens up. Key in

mount -rw -o remount /

followed by

passwd

to successfully change the root password. Reboot again.

CentOS 6

Restart the server by clicking [RESTART] or click [View Console] and choose the send CTRL+ALT+DEL button which is visible on top to the right.

GRUB boot prompt appears on screen, prompting you to press a key – this prompting waits for few seconds before automatically booting the machine. (If you miss the chance to key in your option, restart VM and follow it from step one).

Once GRUB prompt opens up, type a in the boot command to begin append process. Type single and hit enter.

This should boot your system and open root prompt. Once in root prompt write passwd to reset root-password. Reboot again.

CoreOS requires an SSH key to proceed further

CoreOS makes use of SSH key for authentication in a default mode. Password and Root user are created using Vultr, during which one can select SSH key in VPS. This key is to be given when one has to log in as ‘‘core’’ user mode. Resetting standard root login is achieved when sudo passwd is executed as ‘‘core’’. It requires logging in as ‘‘core’’ via SSH key.

In case of loss/missing SSH key

One can login to ‘‘core’’ user via grub loader editor. Listed below are easy steps to follow in case of missing SSH key.

Restart the server by clicking [RESTART] or choose [View Console] and choose send CTRL+ALT+DEL button which is visible on top to the right.

GRUB boot prompt appears on screen, type e which opens the edit option for boot.(Upon absence of GRUB prompt, one can press any key before machine boot to open the prompt). Typecoreos.autologin=tty 1 (without quotes) at the line which has linux$ in the beginning.

Press F10 or CTRL-X to boot it again. Upon booting, you have successfully logged in as ‘‘core’’. Do not forget to reboot the server after resetting the login.

FreeBSD

The boot menu in FreeBSD offers a user to boot via single-user mode. Press appropriate key to choose single-user mode.

When root prompt opens up, write "passwd" (without quotes). Reboot your server again.

Share this page:

2 Comment(s)

Add comment

Comments

From: mordin_

The FreeBSD instructions in that howto are missing the important step to remount / rw i.e. with: /sbin/mount -uw /

From: Kernel Training

I am follwing your articles. You are posting such a nice articles.