Revoke a leaver's SSH access on remote devices
A person who could log in to your devices has left, or a laptop with their key is lost. Closing that door is easy on one server and slow on a fleet of devices in other people's buildings, some of them offline. Here is what has to change, where the usual setups make it hard, and how to do it with a relay.
What there is to revoke
Three things can let a person in, and removing one does not remove the others:
-
Their own key on the device. Each device decides who gets
in, by the keys in an account's
~/.ssh/authorized_keys. A key on that list works for as long as it is there, whatever happened to the person's account elsewhere. - A shared key. One key pair on every device, or the key the devices use to dial in to a server of yours. Anyone who ever held the private half still holds it after they leave.
- A way to reach the device. A login on your jump host, a seat on your VPN, an account on a relay. A key only matters to someone who can get a connection to the device's SSH server.
So the job is two parts: cut the paths, then take the key off each device. Cutting the path is quick. Taking the key off is the part that gets put off.
Where it gets hard
- The key is on every device. Removing it means a change on each one. Some are offline, behind CGNAT or in a customer's building, so the same job is also the job of reaching them.
-
Whose line is it? An
authorized_keysfile only helps if the comment on each line says who it is. You can list what is there, with fingerprints:ssh-keygen -l -f ~/.ssh/authorized_keys. A line you cannot match to a person is a question, not an answer. The OpenSSH commands on this page are generic and we did not run them for it, nor the hand-edit and Ansible advice below. - A shared key turns one leaver into a rotation. You make a new key, put it on every device while the old one still works, move everyone to it and then remove the old one. That is a change to the whole fleet, so it waits for a quiet week that does not come.
-
Open sessions survive. Taking a key out of
authorized_keysstops new logins. A shell that is already open keeps running until it ends, so check who is logged in on the device and end that session too. - Locking yourself out. Fix the list while you still have a session open, and test the change from a second one. If you cut the wrong path, see locked out after a change.
Options, and what each asks of you
Edit authorized_keys by hand or with a config tool
The plain answer, and fine when you have a few devices you can reach. List the keys, remove the line, and keep the rest, and keep your own session open until the new list is tested. With a tool such as Ansible you can push the same list to many devices at once, which works when every device is reachable from where you run it. Devices behind NAT are not, so you also run a path to them: see jump hosts and NAT.
Cut the path: the jump host or the VPN
If people reach devices only through a jump host or a VPN you run, deleting their login there stops new connections. It does not touch the keys on the devices, and a shared key the devices use to dial in to that host is still known to them. Treat that key as exposed and replace it on each device.
A hosted relay with per-device key lists
With a relay the two parts are separate and you can do them in order. First, remove the person from the team, which stops their shells at once. Then take their key off the devices, as a signed change. The rest of this page is that route, and its limits.
RescueShell steps
This is the order we would use. We have not run these exact commands for this page, and a team's own setup differs: check them on a test device first. The agent on each device connects out to our relay. The device's own OpenSSH server checks a key from the device's own list of trusted keys, and our servers cannot add a key to that list or take one off it.
1. Remove the person from the team
An admin does this under Team, then Members. Removing someone, or demoting them to viewer, ends their open shells right away and stops them opening new ones through RescueShell, on every device, online or not. The relay reads a person's role on each request. See roles.
That is access through us. It does not edit any device, so the key is still on each device's list. If the person can reach a device another way, for example your own VPN or its SSH port on a LAN, the key still works there. Cut those paths too.
2. Find the key on each device
Open the device under Devices and its
Checklist. It lists the trusted keys the device last
reported, by fingerprint. That is what the device told us, and it can be a
little out of date: the device is the authority. Match the fingerprint to the
leaver's public key with ssh-keygen -l -f their_key.pub.
3. Remove the key with a signed change
The device only takes a change that is signed by a key it already trusts, so sign with your own key, not the leaver's. From the CLI:
rescueshell trust pump-07 --sign-with ~/.ssh/id_ed25519 --remove-key ./leaver.pub
Change pump-07 to the device name, --sign-with to
your own private key and --remove-key to the leaver's public key,
as a file or the key line. The command shows the key fingerprint and the key
that signs, and asks before it sends anything. The device checks the signature
itself, then applies the change. The device refuses a list with no key left or
no login account, so you cannot remove the last one this way.
For devices installed as a group, the same change can be signed in one run for
every online device in the group:
rescueshell trust --group NAME --sign-with KEY --remove-key FILE.
Add --check instead of --sign-with to list the
devices that still differ. The CLI refuses a batch that would remove the key
that signs it. If a device keeps the old list, see the limits below.
4. If nothing left on the device can sign
Run the install command again on the device as root. It asks for a
registration pass, replaces the device's list with the one in the command, and
prints will remove: for each key or account that would go, before
it asks [y/N].
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 the device's name. Be careful with the last flag:
--trust-keys-from re-trusts every key in that account's
authorized_keys, including the leaver's. Remove the leaver's line
from that file first, or replace the last flag with
--trust-key 'ssh-ed25519 AAAA… you@laptop' --allow-user ACCOUNT.
See add a device for the other options.
What it does not do
- A device that is offline keeps its old list. A trust change needs the device connected, and nothing is queued. If it reconnects first, the change is refused as stale. Run it again when the device is back. The Checklist shows what each device last reported, which is a hint and not proof.
- It does not know that someone left. Removing the person and their key are steps you take. There is no link to your HR system.
- It only changes the device's own list of trusted keys. A key or password on another service of yours, or a copy of a private key someone kept, is yours to deal with.
- It is a shell on one device, one open shell at a time, with port forwarding through a session off. OpenSSH only, on Linux. The device needs outbound HTTPS on port 443 and WebSocket allowed. Traffic goes through the relay, which is a dependency: if it is unreachable you cannot open a shell, and we offer no uptime SLA.
- If you lose every key a device trusts, nobody can sign for it, and the fix is the install command above.
How to choose
-
A few devices you can reach, and a short list of people: edit
authorized_keysand keep your own session open. - Many devices behind NAT, with people coming and going: a relay lets you remove the person in one step and then take the key off each device, online ones in a batch.
- Either way, give each person their own key and write down whose it is. A shared key is what makes this a fleet-wide job. The options for reaching the devices at all are in reverse SSH vs a VPN mesh vs a hosted relay.
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.