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.

Published
Updated

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.

Hetzner dashboard with rescue mode


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:

bash
ssh root@YourServerIP
Important

If 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:

bash
fdisk -l
// You are looking for something like
// /dev/sda1   528384 80003038 79474655  37.9G  Linux filesystem

5. Mount the Filesystem

bash
# 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

bash
chroot /mnt

This gives you root access to your real system from the rescue environment.


🔐 Regain Root Access

7. Reset Root Password

bash
passwd root

Enter a new password when prompted.

8. Enable SSH Root Login

Edit the SSH config:

bash
nano /etc/ssh/sshd_config

Make sure these two lines are set:

bash
PermitRootLogin yes
PasswordAuthentication yes

Exit chroot so you can restart ssh service

bash
exit

Restart the SSH service:

bash
systemctl restart ssh

🔄 Final Steps

9. Unmount

bash
umount /mnt/run
umount /mnt/sys
umount /mnt/proc
umount /mnt/dev
umount /mnt

10. Reboot

bash
reboot

After 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.