SSH Key Lost: Unable to Connect to Hetzner Server

Abstract: Regain SSH access to a Hetzner server by using the Rescue System to mount the root filesystem and inject a new public key into authorized_keys.

Created: 2026-10-07 by

You can regain access to your Hetzner server by using the Rescue System. Boot into this mode via the Robot interface, mount your root filesystem, and edit the authorized_keys file directly from the command line. This method bypasses standard SSH authentication entirely, allowing you to inject a new public key and restore remote shell access without needing the original credentials.

Accessing the Hetzner Robot Interface

The first step in recovering a lost SSH key is gaining administrative control over the server hardware through Hetzner’s online management portal. You must log in to the Hetzner Robot web interface using your account credentials. Once logged in, navigate to the Servers menu and select the specific server that has become inaccessible due to the missing key. On the server details page, locate the Reset or Change Password section. Look for the option labeled Rescue System. Click on this option to initiate the rescue boot process. You will be presented with a form where you need to select an operating system version. It is highly recommended to choose a stable Linux distribution such as Debian 11 or Ubuntu 20.04 LTS, as these environments are well-supported and contain all necessary utilities for file manipulation. After selecting the OS, click Activate Rescue System. The system will generate a temporary root password. Copy this password immediately, as it will only be displayed once. Save it securely, as you will need it to log into the rescue environment via SSH. Note that activating the rescue system requires a short downtime, typically between one to three minutes, during which the server reboots.

Connecting to the Rescue Environment

Once the server has rebooted, you can connect to it using the temporary root password provided by the Robot interface. Open your local terminal application and establish an SSH connection to the server’s IP address. Use the username root and the temporary password generated earlier. For example, run:
ssh root@your_server_ip
If you encounter connection issues, ensure that your local firewall is not blocking outbound SSH traffic. After successful authentication, you will have full root privileges within the rescue environment. This environment is isolated from your main operating system, meaning any changes you make here do not affect the live system until you explicitly mount its partitions. Before proceeding, verify the network connectivity and disk layout. Run the lsblk command to list all block devices. Identify the partition that corresponds to your main root filesystem. In most standard Hetzner setups, this will be something like /dev/sda1 or /dev/nvme0n1p1. Do not guess the device name; incorrect mounting can lead to data loss or failure to find the correct user directories.

Mounting the Root Filesystem

With the rescue system active and connected, the next critical step is to mount your actual server’s root filesystem. This allows you to read and write files on your persistent storage. Create a temporary directory to serve as the mount point:
mkdir /mnt/root
Now, mount the identified root partition to this directory. Assuming your root partition is /dev/sda1, execute:
mount /dev/sda1 /mnt/root
If your setup uses LVM (Logical Volume Manager), the device path might differ. In such cases, you may need to activate the volume group first using vgs and lvs commands to identify the correct logical volume. However, for standard installations, direct partition mounting is sufficient. Verify the mount was successful by running df -h /mnt/root. You should see your root partition listed with available space.

Injecting the New SSH Key

Now that your root filesystem is mounted at /mnt/root, you can modify the SSH configuration. The SSH daemon checks the ~/.ssh/authorized_keys file for each user to determine who is allowed to log in. You need to append your new public key to this file for the user account you wish to access. First, identify the home directory of the target user. If you want to add the key for the root user, the path is /mnt/root/root/.ssh/authorized_keys. If you are adding it for a different user, such as admin, the path would be /mnt/root/home/admin/.ssh/authorized_keys. Generate a new SSH key pair on your local machine if you haven’t already:
ssh-keygen -t ed25519
Copy the content of your public key file (~/.ssh/id_ed25519.pub) to your clipboard. Then, append it to the authorized keys file on the server. You can use the echo command with redirection:
echo "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI... [email protected]" >> /mnt/root/home/username/.ssh/authorized_keys
Replace the placeholder string with your actual public key. Ensure there are no extra spaces or newlines that could corrupt the key format. If the .ssh directory does not exist, create it using mkdir -p /mnt/root/home/username/.ssh before appending the key. After writing the key, set the correct permissions to ensure SSH accepts the file:
chmod 700 /mnt/root/home/username/.ssh
chmod 600 /mnt/root/home/username/.ssh/authorized_keys
Finally, unmount the filesystem and deactivate the rescue system in the Hetzner Robot interface. Reboot the server normally. You should now be able to connect using your new private key.

Troubleshooting Common Issues

If you still cannot connect after following these steps, check the ownership of the .ssh directory. It must match the user ID of the account you are trying to access. Incorrect ownership will cause SSH to reject the key silently. You can fix this with:
chown -R username:username /mnt/root/home/username/.ssh
Additionally, verify that the SELinux context is not blocking access if you are using CentOS or RHEL-based systems. Although less common in basic setups, mislabeled contexts can prevent SSH from reading the authorized keys file. For more information on resolving SSH connectivity errors, see our guide on [Troubleshooting kex_exchange_identification Error in Linux SSH Connection](/news/1065851/kex-exchange-identification-error-in-linux-ssh-connection). Another useful resource covers [Closing SSH Connection with Keygen](/news/1044733/closing-ssh-connection-with-keygen) to help manage your key lifecycle effectively.

Frequently Asked Questions

Can I recover my SSH key if I forgot the passphrase?

No, SSH keys are encrypted locally on your machine. If you lost the private key file itself, you cannot recover it. You must generate a new key pair and add the new public key to the server, which is what this guide explains how to do via the rescue system.

Does activating the rescue system delete my data?

No, activating the rescue system only boots a temporary OS from Hetzner’s infrastructure. Your existing data on the hard drive remains intact. You are merely mounting your existing drive to make it accessible for editing.

What if my server uses LVM instead of standard partitions?

If your server uses LVM, you will need to activate the volume groups in the rescue environment before mounting. Use commands like vgchange -ay to activate volumes, then mount the logical volume path (e.g., /dev/mapper/vg-root) to /mnt/root.

Why did my SSH connection fail after adding the key?

This is usually caused by incorrect permissions or ownership. The .ssh directory must be owned by the user and have permissions set to 700. The authorized_keys file must be owned by the user and have permissions set to 600. Any deviation will cause SSH to ignore the key for security reasons.

Is it safe to edit files in the rescue system?

Yes, it is safe as long as you mount the correct partition. Always verify your mount point with lsblk and df before making changes. Accidentally formatting or overwriting the wrong partition is the primary risk, so double-check device names carefully.
Tags: Linux SSH

Latest News

How to Display Output of xterm Command in Terminal Screen using Cron

Resolve the inability to display xterm output in a terminal screen from cron by redirecting logs or using wall instead of insecure X11 workarounds.

Read More
Expose Local Server on VPS Preserving Real Client IPs (OS Level)

Resolve VPS logging showing only gateway IPs by configuring reverse proxies to forward real client addresses via X-Forwarded-For headers.

Read More
How to Clear Recent Files History in Linux without Deleting Actual Files?

Clear recent files history in Linux by deleting ~/.local/share/recently-used.xbel without removing the actual files.

Read More
Best HDD Copy Strategy: Manually Syncing and Rewriting Scratch

Resolve data drift between two 4TB hard drives by using rsync with the --delete flag to manually sync and rewrite scratch data for an exact mirror.

Read More
Understanding Bash Prompt Abbreviations: An Overview

Resolve repetitive typing errors by creating and persisting Bash aliases in the .bashrc file for improved command-line efficiency.

Read More
Free Tools and Methods to Log Real-Time Performance Details in Task Manager

Log real-time CPU and memory metrics to CSV files using Windows Performance Monitor Data Collector Sets to troubleshoot system slowness.

Read More
Contact Qatar Airways Customer Service: Phone Number, Help Center, and More

Resolve urgent Qatar Airways reservation issues like flight changes and baggage claims using the US phone number +1801-855-5905 or online self-service tools.

Read More
Windows 11: Alt Codes Displaying Wrong Characters - Solutions

Resolve Windows 11 Alt codes showing wrong characters by verifying the US keyboard layout and enabling Num Lock.

Read More
Run Programs with Elevated Privileges: A Comprehensive Guide

Eliminates the need to type sudo for frequent administrative tasks by configuring .bashrc aliases or functions.

Read More
Dynamically Changing Dates in Excel Formulas Using Cells

Eliminate manual date updates in Excel by using cell references to create dynamic formulas that automatically adjust calculations when input dates change.

Read More
Granting Edit Access to a Specific Excel Sheet in an Office 365 User Email ID-Based Login

Excel Online lacks native sheet-level permissions, so users must split workbooks or use worksheet protection to isolate edit access for specific tabs.

Read More
Creating Network Load on Local Wi-Fi from One PC

Generate sustained Wi-Fi bandwidth load from a single PC using a VM SFTP server to test router stability and throughput.

Read More
Changing the Default Editor for Batch Files in Windows 11's File Explorer

Resolve the issue of batch files opening in Notepad by changing the default editor to a preferred application like VS Code.

Read More
Gain WiFi Connection Minutes Before Losing it by Changing MAC Address

Bypass MAC address filtering to restore WiFi connectivity temporarily when a device is blocked by network administrators.

Read More
Photos Folders Turned Black: Troubleshooting Picture Applications on Windows

Resolve black screens in Windows Photos by resetting the app, updating graphics drivers, and repairing system files.

Read More
Troubleshooting High CPU Temperature Values: A Step-by-Step Guide

Resolve high CPU temperatures and thermal throttling by monitoring with Speedfan, cleaning dust from cooling components, and replacing degraded thermal paste.

Read More
Make cURL establish TLS connection with CA unknown

Resolve cURL TLS connection failures with unknown or self-signed certificates by using the --insecure flag to bypass CA validation.

Read More
Troubleshooting Incorrect Network Metrics Values in Grafana, Prometheus, InfluxDB, and Telegraf

Fix incorrect network metrics in Grafana, Prometheus, InfluxDB, and Telegraf by verifying interface selection, resolving unit mismatches, and handling counter resets.

Read More
Start Another Terminal Window (cmd.exe) Windows Repair/Troubleshoot

Provides step-by-step instructions to access the Windows Command Prompt via bootable media for advanced system repair and troubleshooting.

Read More
Thinkpad P1 Gen 6: Sudden Thunderbolt 3 Dock USB-C Charging Stopped Working

Resolve sudden Thunderbolt 3 dock USB-C charging and internet failure on ThinkPad P1 Gen 6 by updating firmware, resetting the dock, and adjusting power settings.

Read More
ASUS Windows 11 Laptop: Internet Connection Issue with Hotspot

Resolve ASUS Windows 11 laptop spinning wheel issue when connecting to mobile hotspot by resetting network stack, disabling IPv6, and adjusting power settings.

Read More
Developing iOS Project with Firebase: Logging in and Sending Push Notifications

Integrates Firebase to enable secure user authentication and push notifications in iOS applications.

Read More
Troubleshooting Bash Script with Suspected Issues of Spaces, Dashes, Filenames and Quoting

Resolve Bash script failures caused by word splitting, globbing, and special characters in filenames by applying proper quoting techniques.

Read More
Populating OneDrive Folder for Local Backup without Affecting Remote Files

Prevent OneDrive from deleting remote files during Windows reinstallation by unlinking the account or using symbolic links to isolate local data.

Read More
Force First Frame as Keyframe Without Re-encoding: A Quick Solution

Resolve inaccurate seeking and playback glitches by re-encoding video to ensure the first frame is a valid keyframe.

Read More
Find Information in Database Using WSL (Ubuntu) on Windows-10

Resolve database connection issues from WSL Ubuntu on Windows 10 by configuring client tools and network access to query remote or local servers.

Read More
Configuring a New Router with Different Networks: One Family, One Guest

Resolve IP conflicts and isolate guest traffic by configuring a second router with a distinct subnet via its WAN port.

Read More
Quickly Open Multiple Stock Websites with a Single Command

Solve the problem of manually opening multiple stock research websites by creating a single command to launch them simultaneously on Windows, macOS, or Linux.

Read More
Improved Adobe Acrobat Search Experience: Access Advanced Search with Ease

Access advanced search filters like case sensitivity and regex in Adobe Acrobat by clicking More Options in the Find bar.

Read More
Port Forwarding VM via OpenVPN: A Comprehensive Guide

Configure OpenVPN server and iptables to forward specific ports from VPN clients to a virtual machine's internal IP address.

Read More
Understanding Partitions in the 1980s: A Look Back at MS-DOS and Master Boot Record

Explains how the Master Boot Record and partition table enabled MS-DOS to manage multiple disk volumes on a single physical drive.

Read More
Windows 10 Enterprise: Keyboard Not Detected in Managed Organization with Admin Privileges

Resolve Windows 10 Enterprise keyboard detection failures caused by Group Policy restrictions, driver corruption, or USB enumeration errors.

Read More
Can't Find x86_64 Versions of Applications on MacOS arm64 (M1)

Resolve missing x86_64 app issues on M1 Macs by installing Rosetta 2 and reinstalling apps as universal binaries.

Read More
How to Hide Installation Source for an Android App

Manage Android app installation source visibility by using USB transfers or file managers to reduce browser traces and isolate data via work profiles.

Read More
Connecting Momentus 4200.2 ST9808210A Hard Drive via USB Cable

Resolve inability to access Seagate Momentus 4200.2 ST9808210A hard drive by connecting it via USB using a compatible SATA-to-USB adapter and configuring the disk in Windows.

Read More