What to do when you are locked out of your VPS
The browser-based console gets you back in even when SSH will not, and then the same handful of causes cover almost every lockout.
Getting locked out of a VPS is nearly always self-inflicted — a firewall rule that blocked SSH before allowing it, an sshd_config typo, or password authentication disabled before a key was actually confirmed working. The good news is that none of these need to be permanent, because your host's browser-based console gets you into the server directly, entirely bypassing the network layer that SSH depends on.
Step 1: use the console, not SSH
Every VPS provider offers some form of browser-based console — often called VNC, KVM console, or similar — accessible from your account's control panel rather than over the network. It connects to the server's virtual screen directly, the same way a monitor and keyboard plugged into a physical machine would, so a firewall rule or a broken SSH daemon has no effect on it at all.
Log in to your hosting account, find the console option for the affected VPS, and open it. You should see a normal login prompt exactly as if you were sitting in front of the machine.
The console is a local login, not an SSH session, so a key-based setup does not apply to it. Use your root or sudo account's password. If you never set one, or cannot remember it, your host's control panel or support team can typically reset it.
Step 2: diagnose what actually locked you out
| Symptom | Likely cause | Fix |
|---|---|---|
| Connection refused, immediately | Firewall blocking port 22, or SSH service not running | Check the firewall rule; check systemctl status ssh / sshd |
| Connection times out with no response | Firewall dropping the connection silently rather than rejecting it | Same as above — check firewall rules first |
| Permission denied (publickey) | Password authentication was disabled before a key was confirmed working | Re-enable password auth from the console, or add a working key |
| Prompted for a password you don't have | Wrong username, or the account's password was never set | Reset it from the console |
Fixing a firewall lockout
From the console, check the current rules:
sudo ufw status verbose # ufw
sudo firewall-cmd --list-all # firewalld
If SSH is missing from the allowed list, add it back:
sudo ufw allow OpenSSH
sudo ufw reload
sudo firewall-cmd --permanent --add-service=ssh
sudo firewall-cmd --reload
If a rule was added that blocks SSH more specifically — restricted to a wrong IP address, for instance — find and remove that specific rule rather than disabling the firewall entirely:
sudo ufw status numbered
sudo ufw delete NUMBER
Fixing an SSH configuration lockout
If PasswordAuthentication no was set before a key login was actually confirmed, or a typo in sshd_config is stopping the service from starting at all, edit it from the console:
sudo nano /etc/ssh/sshd_config
Set PasswordAuthentication yes temporarily, save, and restart the service:
sudo systemctl restart ssh # Debian / Ubuntu
sudo systemctl restart sshd # RHEL / Rocky / AlmaLinux
If the service refuses to restart at all, check what it is objecting to before assuming the whole file needs rewriting:
sudo sshd -t
This tests the configuration and reports the exact line causing a problem, which is almost always faster than reading the entire file looking for a typo.
Once SSH is reachable again, connect normally from a second terminal, confirm it works, and only then re-disable password authentication — following the same test-before-you-trust sequence covered in connecting to a VPS over SSH.
Locked out because the disk is full
A filesystem at 100% can stop SSH from completing a login even though the service itself is technically running, because writing session and authentication files fails silently. If the console shows the login prompt but the connection then hangs or drops, check disk space from the console:
df -h
Clear obvious space — old log files, a stale backup archive, a package cache — and try SSH again once a filesystem is no longer completely full:
sudo apt clean # Debian / Ubuntu — clears the downloaded package cache
sudo dnf clean all # RHEL / Rocky / AlmaLinux
If you cannot remember any password at all
Most hosts can reset the root password for a VPS from their side, sometimes through the control panel directly and sometimes by request. Once reset, log in via the console with the new password, then either restore your original key-based access or create a fresh sudo account, following how to create a non-root sudo user.
Preventing this from happening again
- Always allow SSH in the firewall before enabling it, never after.
- Always confirm a key works in a brand new session before disabling password authentication.
- Keep an existing working session open while changing anything in
sshd_configor the firewall — never make both changes in the same session with nothing open as a fallback. - Know where your host's console is located before you need it — check this now, not during an actual lockout.
If you have worked through this and are still unable to get back in, contact us with the server's hostname or IP and what you have already tried, and we can advise from our side.
Related reading
SSH is how you control a VPS from the command line, and setting it up properly the first time saves you a lot of trouble later.
How to set up a firewall on your VPSHow to enable and configure a firewall on your VPS with ufw or firewalld, without accidentally shutting yourself out over SSH.
How to create a non-root sudo userWhy root should not be your daily account, and the exact commands to create a proper sudo user in its place on any major distribution.
How much RAM does my VPS need?It depends what is running, but free -h on an existing server and a look at what each extra service costs gets you a real answer fast.