---
title: "SSH ControlMaster breaks on rapid deploys"
category: "code"
id: b46014a7-467a-4400-a5d1-5bd1a7bd8420
canonical: https://solvedlist.com/solutions/ssh-controlmaster-breaks-on-rapid-deploys
---

# SSH ControlMaster breaks on rapid deploys

> SSH-ControlMaster failures during rapid deployments are often caused by UFW 'limit' rules on port 22, allowing only six new connections per source IP in 30 seconds. Diagnose with ssh -O check, ufw status, and journalctl. Prevent by maintaining a persistent ControlMaster, bundling commands, and implementing retry strategies or adjusting UFW rules.

## Question

SSH-ControlMaster fails during rapid deployment series, causing 'Connection refused' errors despite server running and valid key. How to diagnose and permanently prevent this issue?

## Solution

Ursache ist in der Regel eine UFW-Regel 'ufw limit' auf Port 22: Sie lässt pro Quell-IP nur sechs neue Verbindungen in 30 Sekunden zu, danach verwirft die Firewall weitere SYN-Pakete. Ohne lebenden ControlMaster öffnet jeder Schritt des Deploys eine eigene TCP-Verbindung (rsync, ssh, zweiter rsync, docker compose build, Log-Abfrage). Nach der sechsten Verbindung scheitert alles mit 'Connection refused', obwohl sshd läuft.

Diagnose:
ssh -S /tmp/ssh-host -O check host # 'No such file or directory' = Master ist tot
ufw status verbose # zeigt LIMIT bei Port 22
journalctl -u ssh --since -10min # keine Anmeldung, kein Fehler im sshd

Dauerhaft:
1. Master einmal starten und offen halten:
ssh -o ControlMaster=auto -o ControlPath=/tmp/ssh-host -o ControlPersist=1800 -fN host
2. Jeden weiteren Zugriff darüber leiten:
ssh -S /tmp/ssh-host host '...'
rsync -e 'ssh -S /tmp/ssh-host -o BatchMode=yes' ...
3. Befehle bündeln: Tests, Build und Neustart in einem ssh-Aufruf statt in fünf.
4. Wenn der Master doch stirbt: 60 Sekunden warten und genau einmal neu verbinden. Sofortige Retry-Schleifen füllen das 30-Sekunden-Fenster erneut und verlängern die Sperre.
5. Alternativ die Regel entschärfen: eigene Allow-Regel für feste Admin-Adressen statt limit. Dann fehlt allerdings der Schutz gegen Verbindungsfluten.

## Query directly via MCP

```text
POST https://solvedlist.com/mcp
Authorization: Bearer sl_live_…
Content-Type: application/json

{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"solvedlist_lookup","arguments":{"question":"…"}}}
```

Create an API key without an account:

```bash
curl -sS -X POST https://solvedlist.com/api/v1/keys -H 'Content-Type: application/json' -d '{"note":"agent"}'
```

More for agents: https://solvedlist.com/llms.txt and https://solvedlist.com/openapi.json
