Reset root password of a VM

11,161

To recover the root password, you will need to boot into single user mode. In many distrobutions there is a drop down option to let you select at the boot loader. If you are using GRUB, you can select the version of the OS kernel you would like to boot, hit the "edit" key (e I believe), and then append the word "single" to the end of the kernel parameters string. You can find Ubuntu specific instructions here.

Once you have booted into single user mode, you should see a prompt like this:

sh#

To reset the root password, type:

passwd root

At this point you will be prompted to enter a new password and to confirm the password. You can also modify the /etc/sudoers file to add your user back to the sudoers group.

Share:
11,161

Related videos on Youtube

user219798
Author by

user219798

Updated on September 18, 2022

Comments

  • user219798
    user219798 over 1 year

    I removed (distrattament) my "sudo" user from sudo group user, I can't use root because I don't know a password for root.

    I have an Ubuntu virtual machine and when I open Recovery Menu is limited read-only menu. If I select "root Drop to root shell prompt" the message is "Give root password for maintenance" ... but I don't know the root password.

    How can I reset root password?

  • user1984103
    user1984103 about 11 years
    Note, you should modify the /etc/sudoers file and add yourself back to sudoers instead of enabling the root account. The root account is disabled for a reason.
  • Matthew
    Matthew about 11 years
    I disagree on that front - I work on Solaris, HPUX, and Red Hat boxes all day, and we have never had an issue with root login being enabled. Especially given a lot of apps we run require root SUID. If someone has absolutely no idea what they are doing, maybe it is a valid precaution. But I tend to consider it security by obscurity - the root account still exists (and you can exploit up to it), the wheel group still exists. Different approaches I guess :)
  • wersimmon
    wersimmon about 11 years
    @Matthew: Which means you really aren't the target market for Ubuntu. The Ubuntu wiki has a good breakdown of the advantages and disadvantages of using sudo over root.
  • X.LINK
    X.LINK over 9 years
    @Matthew: Single user mode can be disabled. Solaris, HP UX and Red Hat are enterprise-class Unix where such ability is considered as an exploit and therefore disabled.
  • Mathieu K.
    Mathieu K. about 6 years
    CentOS <> Ubuntu.
  • Graham Leggett
    Graham Leggett almost 4 years
    Also, broken link.