rescueshell Start trial

Locked out of SSH after a firewall change?

You enabled a firewall, moved the SSH port or tightened sshd_config, and the next ssh hangs or is refused. The device is still running, and it is not next to you. Which way back in exists depends on what you broke, so start by working that out.

Work out what you cut

  1. Timeout. The address is right and nothing answers. Usually a firewall rule, a cloud security group, or an address that changed. The SSH server may be running fine.
  2. Connection refused. The host answers and nothing listens on that port. sshd is stopped, failed to start on a bad config, or listens on a different Port or ListenAddress than the one you are trying.
  3. Permission denied (publickey). sshd is fine and refuses you on purpose: PasswordAuthentication no before a key was in place, an AllowUsers or DenyUsers line, a changed PermitRootLogin, or a wrong mode on the home directory or ~/.ssh. If nothing changed and ssh simply refuses a key, the publickey how-to covers the everyday case.

nc -vz host 22 from your laptop separates the first two: "refused" answers at once, a timeout does not. If you did not just change a firewall or sshd, the timed out and refused how-to is the everyday version of the first two.

Ways back in

A console

A keyboard and screen on the device, a hypervisor or cloud provider's serial or VNC console, or a rescue mode. It fixes all three cases because it does not use the network path you broke. It is also the one thing you cannot count on for a device in someone else's building.

Someone on site

They can reboot it, which undoes any firewall rule that was never saved. It does not undo one that was, or a bad sshd_config, and it costs a person's time.

Mount the disk elsewhere

Boot a live system or move the disk or SD card to another machine, and edit the file. It works for every case and takes the device down while you do it.

A second path that does not use the one you changed

Something already set up that reaches the device another way: a management network, a second interface, a VPN, a reverse tunnel, or a hosted relay. It has to exist before the change. Each one is also a thing to keep running; the comparison goes through what they ask of you.

Make the next change safe

These habits cost a minute and need nothing installed.

RescueShell as the second path

An agent on the device keeps one outbound HTTPS connection to the relay. When you open a shell, the agent connects to the device's own SSH server at 127.0.0.1 port 22 and your session runs there. That decides which lockouts it survives, so read the next two lists before you rely on it.

It still works when you cut:

It needs the firewall to leave two things alone: loopback traffic, and outbound HTTPS to the relay. A default-deny rule on outgoing traffic cuts the agent too.

It does not help when:

So it covers the most common self-inflicted lockout, a firewall or a security group, and not a broken sshd. It has to be installed first. A device you are already locked out of is a job for the console.

1. Check the device

uname -m
openssl version
command -v curl
sudo sshd -t

It needs Linux on amd64, arm64, armv7 or armv6, and curl or wget. Any other CPU stops with unsupported CPU. The release signature is checked with OpenSSL 3; without it, pass --sha256. OpenSSH has to be installed and running, and Dropbear is not supported. For a device with no OpenSSH, see install without OpenSSH.

2. Install

In the web app, open Devices, press Add device, name it and press Create pass. Then run this on the device as root, while you still have access:

curl -fsSL https://releases.rescueshell.com/latest/install.sh | sh -s -- \
  --base-url https://releases.rescueshell.com/latest --relay https://app.rescueshell.com \
  --name pump-07 --trust-keys-from pi

Change pi to the account whose keys you log in with, and pump-07 to a name for the device. The installer lists each key it will trust by fingerprint and asks you to confirm, then asks Registration pass or token:. Paste the pass; nothing shows as you do. It ends with a host key: line. Keep it, because the browser asks for it the first time you open a shell. See add a device for the other options.

The agent starts at boot under systemd, OpenRC, procd on OpenWrt or an init script, whichever the device uses. Check it with rescueshell-agent --status. The installer adds a drop-in file for sshd and does not edit your main sshd_config.

3. Prove it before you change anything

When the device shows as connected under Devices, open a shell from the browser, or from your terminal with the CLI, with your usual SSH session still open. Only then make the firewall or sshd change. After it, open a shell the same way and check that it still works.

The device needs outbound HTTPS and nothing inbound. When the link drops, the agent retries every 60 seconds, five times, then waits 30 minutes and starts over, so the device comes back by itself, whatever address it got.

What it does not do

If the shell does not open, see the shell does not open.

Try it on one device

The first device is free to try with no card, for 30 days from when it connects, not from when you sign up. Start a trial.