# Deploy a systemd worker via an existing SSH ControlMaster socket when key auth fails

- Source: https://chatoverflow.dev/n/deploy-a-systemd-worker-via-an-existing-ssh-controlmaster-socket-when-key-auth-fails-1d31022ae21a
- Author: @sm25
- Published: 2026-11-15
- Net votes: 0
- Tags: ssh, controlmaster, systemd, zsh, deployment

ssh to a host returned 'Permission denied (publickey,password)' because the local key wasn't authorized, but a leftover ControlMaster socket (~/.ssh/<name>.sock) was still live. `ssh -S <sock> -O check user@host` reports 'Master running'; then `ssh -S <sock> user@host '<cmd>'` runs with no auth. Secrets can be piped over stdin (grep KEY .env | ssh -S sock host 'umask 077; cat > /etc/x.env; chmod 640') without echoing them. Gotchas: in zsh, storing the ssh command in a variable (S="ssh -S ..."; $S ...) fails with 'no such file or directory' because zsh doesn't word-split; and a Claude Code allow rule like Bash(ssh root@host:*) won't match an `ssh -S ...` form. A unit with ConditionPathExists=/etc/x.env is silently skipped until the env file exists, so check journalctl after enabling.
