Changing the SSH key

Last change on 2026-06-02 • Created on 2026-06-02 • ID: CL-65B22

Please note that we can only store SSH keys on cloud servers when the server is created. For more information, see the FAQ entry "I have added my SSH key to the Hetzner Console, why can I not access my existing server via my SSH key?".

If you can no longer access your server because password authentication is blocked and you lost your SSH key, you can regain access by adding a new SSH key on the server via the rescue system.

To add a new SSH key via the rescue system, do the following:

  1. Enable the rescue system

    As explained in this getting started:

    • Select the server
    • Navigate to "Rescue" and click on "Enable rescue & power cycle"
    • After the reboot, connect to the server as root user.

  1. Create a chroot environment

    Run lsblk and identify the name of the root partition (e.g. sda1).

    Mount the root partition into /mnt and create the chroot environment:

    Replace sda1 with the name of your root partition.

    mount /dev/sda1 /mnt
    chroot-prepare /mnt
    chroot /mnt   

    You can now navigate through the file structure of your server's primary disc.


  1. Edit the SSH keys for the root user

    SSH keys for the root user are stored in /root/.ssh/authorized_keys:

    nano /root/.ssh/authorized_keys

    Add your new public SSH key on a new line. Save the changes using CTRL + X and accept these with ENTER.

    You can now run exit to leave the chroot environment.


  1. Restart the server

    Restart your server to leave the rescue system:

    reboot

After reboot, you should be able to log in as root using the new SSH key.