How to Regain Access to Your VPS on Hetzner (or Any Other Provider
Lost access to your VPS? Here's a step-by-step guide to recover root access using Rescue Mode on Hetzner or similar providers. Learn how to reset your root password, configure SSH, and safely reboot your system.
If you've lost access to your VPS (e.g., forgot your root password or locked yourself out), here’s how to regain control using Rescue Mode, specifically on Hetzner, but applicable to other providers with similar tooling.
✅ Step-by-Step Recovery
1. Enable Rescue Mode
From your VPS provider's dashboard, enable Rescue Mode and select an image (usually Linux-based) with your SSH key or generate one if needed.

2. Get SSH Login Details
Once Rescue Mode is enabled, your provider will supply a temporary username and password for SSH access.
3. Connect via SSH
Open your terminal and connect:
ssh root@YourServerIPIf you get error "REMOTE HOST IDENTIFICATION HAS CHANGED"
Run this command to clear the old key: ssh-keygen -R YourServerIP
🛠️ Inside Rescue Mode
4. Find the Root Partition
List your disks to locate your root filesystem:
fdisk -l
// You are looking for something like
// /dev/sda1 528384 80003038 79474655 37.9G Linux filesystem5. Mount the Filesystem
# 1. Mount your root partition (replace /dev/sda1 with your actual root partition)
mount /dev/sda1 /mnt
# 2. Bind mount important system directories
mount --bind /dev /mnt/dev
mount --bind /proc /mnt/proc
mount --bind /sys /mnt/sys
# 3. (Optional but recommended)
# If using network-related tools or systemd inside chroot:
mount --bind /run /mnt/run
6. Enter Chroot
chroot /mntThis gives you root access to your real system from the rescue environment.
🔐 Regain Root Access
7. Reset Root Password
passwd rootEnter a new password when prompted.
8. Enable SSH Root Login
Edit the SSH config:
nano /etc/ssh/sshd_configMake sure these two lines are set:
PermitRootLogin yes
PasswordAuthentication yesExit chroot so you can restart ssh service
exitRestart the SSH service:
systemctl restart ssh🔄 Final Steps
9. Unmount
umount /mnt/run
umount /mnt/sys
umount /mnt/proc
umount /mnt/dev
umount /mnt10. Reboot
rebootAfter rebooting, your VPS should boot normally and allow root login using the password you just set. Remember to disable password authentication again if you want to keep your server secure with SSH keys only.