Tag: Hetzner

  • How to reset root password on Hetzner Dedicated Server

    How to reset root password on Hetzner Dedicated Server

    If you forget the root password of a Hetzner dedicated server, you need to boot the server into rescue mode, then mount the file system and chroot to the file system, then use the “passwd” command to reset the root password.

    Login to Hetzner

    https://robot.hetzner.com

    Click on the “Server” link on the left menu.

    Hetzner dedicated server

    Click on the server name to show more details about the server.

    Hetzner server rescue mode

    Click on “Rescue”. On the next page, select “Linux” for Operating system. Then click on the “Activate rescue system” button.

    activate rescue mode on hetzner

    On next page, it will show root password for rescue mode. You need this password to login to rescue mode.

    To boot the server into rescue mode, you need to restart the server. For this click on “Reset” tab.

    restart hetzner server

    You have 3 options to reboot the server, select the first option, then click “Send”. If this did not work, you can try the other 2 options. 2nd option is automated power recycling. The third option is a manual restart by the data center technician.

    Once the server is rebooted into rescue, you can log in with SSH using your server IP, user name root, and password shown after you enable rescue mode.

    Chroot the file system

    After login into rescue mode, you need to find the drives used by your Linux installation, and mount it in /mnt/, this may depend on your partition scheme.

    Here are commands assuming /dev/sda2 is / partition and /dev/sda1 is /boot partition.

    NOTE: device name used in your server may be different, you have to find and mount the drives properly

    Mount device for / partition as /mnt

    mount /dev/sda2 /mnt
    

    Mount device for /boot as /mnt/boot

    mount /dev/sda1 /mnt/boot
    

    If you have other partitions, for example, /var and /usr have their own partition, you need to find appropriate partitions and mount them inside /mnt.

    mount --bind /dev /mnt/dev
    mount --bind /sys /mnt/sys
    mount --bind /proc /mnt/proc
    mount --bind /dev/pts /mnt/dev/pts/
    chroot /mnt
    

    Reset root password

    Once you chroot the file system, you can reset root password with the command

    passwd
    

    It will ask for a password and confirm the password.

    Now you can exit from chroot with the command

    exit
    

    Reboot the server back to normal mode with the command

    reboot