Pre-flight: check ssh-add -l before asking user to load a key

Keys are often pre-loaded. Added explicit check-first guidance and
a note to use grep -i (case-insensitive) — a case-sensitive grep
will silently miss keys whose comments use different capitalisation.
This commit is contained in:
Paul O'Reilly
2026-07-18 11:00:52 +12:00
parent 24dcf3bcfc
commit 091fae73e8
2 changed files with 4 additions and 5 deletions

View File

@@ -25,10 +25,9 @@ Git remote URL format: `git@gitea.oreillyit.nz-<user>:<org>/<repo>.git`
Before the first push of a session:
1. Derive the alias: `git remote get-url origin` — the host segment is the SSH alias.
2. Confirm the key is loaded: `ssh-add -l` — the relevant key must appear.
3. Confirm auth: `ssh -T git@<alias>` — expect a Gitea welcome message.
Claude cannot answer a passphrase prompt. If the key isn't loaded, ask the user to `ssh-add ~/.ssh/<keyfile>` before proceeding.
2. Run `ssh-add -l` and read the **full output**. Keys are often pre-loaded — check before asking. Use `grep -i <keyname>` (case-insensitive) to find the relevant entry; a case-sensitive grep will miss keys whose comments use different capitalisation.
3. If the key is present, proceed. Only ask the user to `ssh-add ~/.ssh/<keyfile>` if it is genuinely absent. Claude cannot answer a passphrase prompt.
4. Confirm auth: `ssh -T git@<alias>` — expect a Gitea welcome message.
In non-interactive contexts (CI, container agents, unattended loops), use `GIT_SSH_COMMAND='ssh -o BatchMode=yes' git push` so a missing credential fails fast instead of hanging on a passphrase prompt.