fix(ssh): link only a forwarded agent that holds a key #56

Merged
jmz merged 1 commit from maximus/ssh-rc-live-agent into master 2026-11-23 21:02:57 +00:00 AGit
Member

~/.ssh/rc re-pointed ~/.ssh/auth_sock at every forwarded agent socket. A login from a device whose agent is empty or not answering then broke SSH in every tmux pane.

Incident: 2026-11-23 on spl-vm05, an 18:58 login (agent with no keys) replaced the working 15:03 forward, and ssh jmz@<Pi> failed with Permission denied (publickey).

Change: the link moves only if ssh-add -l exits 0 on the new socket, i.e. its agent holds at least one key. Exit 1 (empty) and exit 2 (not answering) leave the old link in place. timeout 3 is used where it exists, so a hung forward can't stall the login.

Trade-off: a key added to that agent after login doesn't re-link; reconnect with the key loaded.

Testing: bash -n passes. I didn't run the behaviour test (with stub and throwaway agents) in my session because it was refused there. Bear runs /root/ssh-rc-test.sh <worktree>, which uses a stub ssh-add and a temporary HOME and touches no real agent.

🤖 Generated with Claude Code

https://claude.ai/code/session_01XMf4EHUCusHo4yoiNi7VnR

`~/.ssh/rc` re-pointed `~/.ssh/auth_sock` at every forwarded agent socket. A login from a device whose agent is empty or not answering then broke SSH in **every tmux pane**. **Incident:** 2026-11-23 on spl-vm05, an 18:58 login (agent with no keys) replaced the working 15:03 forward, and `ssh jmz@<Pi>` failed with `Permission denied (publickey)`. **Change:** the link moves only if `ssh-add -l` exits 0 on the new socket, i.e. its agent holds at least one key. Exit 1 (empty) and exit 2 (not answering) leave the old link in place. `timeout 3` is used where it exists, so a hung forward can't stall the login. **Trade-off:** a key added to that agent after login doesn't re-link; reconnect with the key loaded. **Testing:** `bash -n` passes. I didn't run the behaviour test (with stub and throwaway agents) in my session because it was refused there. Bear runs `/root/ssh-rc-test.sh <worktree>`, which uses a stub `ssh-add` and a temporary HOME and touches no real agent. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01XMf4EHUCusHo4yoiNi7VnR
fix(ssh): link only a forwarded agent that holds a key
Some checks were skipped
ci / gate (pull_request) Has been skipped
2b31965b39
~/.ssh/rc re-pointed ~/.ssh/auth_sock at every forwarded agent socket.
A login from a device whose agent is empty or not answering then broke
SSH in every tmux pane (2026-11-23 on spl-vm05: an 18:58 login replaced
the working 15:03 forward; ssh to the Pi failed with "Permission
denied (publickey)").

Now the link moves only if `ssh-add -l` exits 0 on the new socket
(timeout 3 s where `timeout` exists).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01XMf4EHUCusHo4yoiNi7VnR
Author
Member

Behaviour test run by Bear on spl-vm05 (/root/ssh-rc-test.sh, stub ssh-add, temporary HOME), all five cases pass:

ok  login with empty agent (ssh-add 1, 0 s): link -> none (want none)
ok  login with good agent (ssh-add 0, 0 s): link -> good (want good)
ok  login with empty agent (ssh-add 1, 0 s): link -> good (want good)
ok  login with broken agent (ssh-add 2, 0 s): link -> good (want good)
ok  login with hang agent (ssh-add hang, 3 s): link -> good (want good)
ALL OK
Behaviour test run by Bear on spl-vm05 (`/root/ssh-rc-test.sh`, stub `ssh-add`, temporary HOME), all five cases pass: ``` ok login with empty agent (ssh-add 1, 0 s): link -> none (want none) ok login with good agent (ssh-add 0, 0 s): link -> good (want good) ok login with empty agent (ssh-add 1, 0 s): link -> good (want good) ok login with broken agent (ssh-add 2, 0 s): link -> good (want good) ok login with hang agent (ssh-add hang, 3 s): link -> good (want good) ALL OK ```
jmz merged commit 2b31965b39 into master 2026-11-23 21:02:57 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
public/dotfiles-public!56
No description provided.