Repository navigation
fix(sshconfig): expand IdentityFile tokens, honor .pub agent identities and IdentityAgent - #90
Merged
flymysql merged 2 commits intoNov 5, 2026
Conversation
…es and IdentityAgent
A config such as
Host *
IdentityAgent /path/to/agent.sock
Host *
IdentitiesOnly yes
IdentityFile ~/.ssh/%n.pub
failed to connect with `cannot read private key ".../%n.pub": ENOENT`:
- `%n` and the other ssh_config(5) tokens were not expanded
(new expandSshTokens: %% %d %h %n %p %r %u %i %l %L, plus ${VAR}).
- A `.pub` IdentityFile, which is OpenSSH's way of saying "use this agent
key", was read as a private key. The pool now authenticates through the
agent and offers the matching key first, or only that key with
IdentitiesOnly yes, so an agent holding many keys no longer trips
MaxAuthTries.
- IdentityAgent was ignored. It now takes precedence over the process
SSH_AUTH_SOCK (`none`, `SSH_AUTH_SOCK` and `$VAR` are honored), for
jump hops too.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Windows cannot listen on a file path (EACCES in the temp dir); an agent there is a named pipe, which ssh2's createAgent treats as OpenSSH. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
With a common agent-based ~/.ssh/config (Bitwarden / 1Password / rbw style):
an ssh-config alias machine can be added, but connecting (e.g. picking a workspace) fails with:
Three gaps:
%nand the other ssh_config(5) tokens inIdentityFilewere not expanded..pubIdentityFile, which is OpenSSH's way of saying "use the agent key matching this public key", was read as a private key.IdentityAgentwas ignored; only the host processSSH_AUTH_SOCKwas used.Fix
lib/sshconfig.js: newexpandSshTokens(%% %d %h %n %p %r %u %i %l %L, plus${VAR}), applied toIdentityFile/IdentityAgent.IdentityAgentandIdentitiesOnlyare now parsed and returned in the resolution (agentSocket,identitiesOnly), for jump hops too. A hop only gets these fields when they are set, so its existing shape is unchanged.lib/pool.js: a.pubkey path means "authenticate through the agent".PreferredKeyAgentwraps the agent so that the matching key is offered first, or only that key withIdentitiesOnly yes. This avoids hittingMaxAuthTrieswhen the agent holds many keys.IdentityAgenttakes precedence overSSH_AUTH_SOCK, andnonedisables the agent. If a.pubidentity is configured but no agent is available, the error now says so instead of reporting a private-key read failure.lib/index.js,lib/registry.js: plumbing foragentSocket/identitiesOnly(active pool, per-machine pools, connection probe).No new dependencies. The system-OpenSSH backend is unaffected: an alias is still handed to
sshverbatim.Tests
test/sshconfig-agent-identity.test.js:IdentityAgent/IdentitiesOnly;SshPoolagainst an in-process ssh2 server through an in-process agent socket holding 3 keys. It asserts that the server is offered only the key matching the.pubfile.npm test: 875 pass, 0 fail.node check.mjsOK.🤖 Generated with Claude Code