ssheep / how it works
Short version: a signed file, a key, and a blind relay. One binary, four roles, as many flocks as you like.
ssheep master flock "myflock" creates the flock, pre-adds the project's
public relay, and prints one shared line to paste on every machine you want in the
flock. Each machine makes its own key and asks to be let in; the next time you run a
command here, it is admitted and shows up in top:
curl -fsSL https://ssheep.xyz/install.sh | sh -s -- --enroll "<line>"
The installer does the joining itself, by the full path it just wrote to, so it works whether or not that directory happens to be on PATH, and it installs the agent as a service so the machine stays in the flock across reboots. Because the machine makes its own key, a leaked line is not a leaked key — but it is a shared secret until it expires, and the master names every machine it admits, so a stranger can be forgotten.
When you would rather count machines before you start — or a machine has to join with
no relay and no later step — --sheep 3 prints one ticket per machine
instead. A ticket carries that machine's private key, so it joins instantly, and it works
once, on one machine.
ssheep master flock "myflock" --sheep 3 curl -fsSL https://ssheep.xyz/install.sh | sh -s -- --ticket "<ticket>"
At any time, ssheep master "myflock" prints the shared line
again, and ssheep master "myflock" --masters 1 mints a spare master.
ssheep run "myflock" -- uptime runs one command on every machine and
streams the output as it arrives. ssheep run "myflock" --script ./deploy.sh
ships a local script and runs it everywhere, and
ssheep copy "myflock" ./app.conf /etc/app.conf puts a file on all of them,
writing to a temporary file and renaming it into place so an interrupted copy never
leaves half a file. ^C reaches the far side and stops the command, and
--json turns the result into data for a script.
Give a machine a label and pick machines by it: ssheep label "myflock" --name
web-1 --set role=web, then ssheep run "myflock" --tag role=web -- ….
Labels live in the signed roster, so they travel with the machine and are revoked with
it. ssheep facts "myflock" prints what the machines are — OS, memory, disk,
uptime, and who is relaying — and ssheep copy -r sends a whole directory
tree while ssheep pull brings one file back.
When something is not working, ssheep doctor says whether
this machine can relay and why not.
| 👑 master | Holds a flock's key, mints tickets, sends commands. Needs no reachable address, so it can be a laptop that is usually off. |
| 🐑 sheep | A managed machine. Dials out and keeps the connection open. Holds only its own private key. |
| 📡 relay | A sheep that happens to be reachable. It runs the relay itself and offers itself to the flock, so nobody has to pick one — the machines that can be reached help, and the rest simply stay sheep. |
| 👤 operator | Can run commands and open shells, but holds no flock key, so it cannot add or remove machines. How you lend a machine without handing over the flock. |
It is one binary. The role is just the subcommand you run, and a machine can hold different roles in different flocks.
It lists who is in the flock and their public keys, and it is signed by the flock key. Every member holds a copy, so there is no database to back up and no server to restore. Keep it in git and you have an audit trail of every machine ever added.
It signs rosters, so it is needed to add or remove a machine — and for nothing else. Keep it offline, and never on a relay.
A relay checks that a connecting machine holds the key the roster says it holds, and then forwards opaque payloads. Master and sheep agree on an encryption key between themselves, using ephemeral keys signed by their permanent ones. The relay sees ciphertext it can neither read nor forge.
A machine is not tied to one flock. Run ssheep master twice and you hold two flocks;
hand a machine two tickets and it serves both. Each flock is entirely its own: its own key,
its own roster, its own relays, its own name for the machine. Nothing is shared between
them, so being in a second flock cannot leak anything into the first.
This is why a machine holds a separate key in every flock. A ticket is minted before the
machine it is meant for has ever been spoken to, so the key has to come from the ticket —
and one key per flock means the same box looks like a different machine to each one.
Everything lives in ~/.ssheep/flocks/<name>/.
ssheep master flock "home" # a second flock, on the same machine ssheep master flock "work" ssheep flock list # every flock this machine knows
One relay can serve many flocks at once, so one reachable machine — one port — can carry several flocks at the same time.
The flock key is the authority — it signs the roster, so whoever holds it can add
and remove machines. Keeping it in one place is tidy and fragile: a flock whose key
lives on one laptop cannot be changed the day that laptop dies. So a master ticket
carries the flock key: mint one with --masters 1 and keep it somewhere else.
A second master can mint tickets, revoke machines and send commands exactly as the
first one does.
A master is not a service: it connects when you type a command. So it asks a relay for the current roster as it connects and takes it when it is newer — that is how a master that has been away for weeks still knows about machines added since.
The cost, plainly: the key now exists in two places. Mint as few master tickets as you can bear, and keep each one at least as safe as the machine you run ssheep from.
ssheep shell "myflock" --name sheep-1 puts a terminal on one machine, and
… -- htop runs one command with a terminal. It is a real ssh session — the
window size, ^C, colours and exit status all work — but the ssh server runs
inside the encrypted tunnel rather than on a port.
ssheep shell "myflock" --all is the fleet version: what you type goes to
every machine at once and the output is labelled by machine. It is line-oriented rather
than a terminal per machine, deliberately — with several machines there is no single
window size to ask for, and several full-screen programs interleaved would be a mess.
That is where the unusual part is: there is no sshd to install on the machine, no
authorized_keys to copy, no known_hosts and no first-use trust,
and nothing listening. The machine is whoever the signed roster says it is, and the
flock key is what proves it — which is also why ssh's own authentication is switched
off: the tunnel already asked who is calling, and only a master can get that far.
The shell runs as the user the agent runs as, so run the agent as yourself — a systemd user unit is the tidy way — and a shell here is your own environment, dotfiles and all. Linux and macOS only, since it needs a pty.
A master cannot know a relay's address in advance — the relay is the machine with the public address, and the master has never spoken to it. So the machine says so itself: every machine asks the flock what it looks like from outside, works out every address it might be reachable at, and offers itself on the connection it already holds to each relay in the flock.
Four things have to line up before the offer is believed. The roster must say that machine may relay — every ticket grants it, and only the master can open that gate. The offer must be signed by that machine, so the relay that carried it could not have rewritten the address and promoted itself. The address must answer with exactly the certificate the offer claims. And the machine must not already be relaying, so a machine that offers several addresses is counted once.
Every address is offered and the first that answers wins, so nobody has
to work out which machine has a public address. If none answers — a machine behind a NAT
with no port forwarding, or a closed port — the master says so and adds nothing, and the
machine stays a sheep. --addr is there to be told the truth when the guess
is wrong.
ssheep master generates a key pair for each new machine, adds its public key
to the roster, re-signs it, and prints a ticket. The printed line installs the binary and
joins in one command, and the ticket says what the machine is to be — a sheep, a
dedicated relay, or another master. The ticket carries that machine's private key, so hand
it over privately. ssheep forget --name sheep-2 removes one and publishes the
new roster; relays drop it within seconds.
A single relay is a single point of failure, which is a strange thing for a tool
whose point is not needing anyone. So a flock keeps a handful: every machine keeps a link
to each of them, and a master tries them in order. Losing one costs the flock nothing, and
top asks every relay and merges the answers, so "online" is a fact about the
flock rather than about whichever relay replied. A new flock starts with the project's
public relay already listed, so it works before its owner has a reachable machine of
their own — and as machines join, the ones that can be reached take over the relaying.
Port forwarding and direct peer-to-peer connections. Files move with
copy and pull, but a directory pull does not exist
yet, and today every byte goes through a relay — a machine behind a NAT with no port
forwarding and no IPv6 cannot relay yet. UPnP and hole punching would sit on top of the
relay rather than replace it. The relay path is the floor.