SSH: fall back to default identity files when agent lacks the key#312231
Merged
roblourens merged 2 commits intomainfrom Apr 23, 2026
Merged
SSH: fall back to default identity files when agent lacks the key#312231roblourens merged 2 commits intomainfrom
roblourens merged 2 commits intomainfrom
Conversation
Switch SSH auth to ssh2's authHandler callback, walking an ordered queue of attempts: explicit privateKeyPath -> agent (if SSH_AUTH_SOCK) -> each existing default identity file. Mirrors OpenSSH client behavior so a host that accepts ~/.ssh/id_rsa still connects when the agent doesn't have it loaded, without needing an explicit IdentityFile in ssh config. Also import proper ConnectConfig typings from ssh2 instead of using Record<string, unknown>. (Written by Copilot)
Contributor
There was a problem hiding this comment.
Pull request overview
Updates the SSH remote agent host connection logic to more closely match OpenSSH key fallback behavior by using ssh2’s authHandler with an ordered list of authentication attempts, and adjusts tests/linting accordingly.
Changes:
- Switch
_connectSSHto build an ordered auth-attempt queue and use a newmakeAuthHandlerto drive ssh2 authentication. - Refactor reconnect logic to always use Agent auth mode while optionally surfacing a non-default
IdentityFileas an explicit key attempt. - Replace prior auth-config tests with
_buildAuthAttemptsandmakeAuthHandlerunit tests; allowssh2in ESLint config.
Show a summary per file
| File | Description |
|---|---|
| src/vs/platform/agentHost/node/sshRemoteAgentHostService.ts | Introduces auth-attempt queue + authHandler, reconnect simplification, and new test seams for agent/key-file access. |
| src/vs/platform/agentHost/test/node/sshRemoteAgentHostService.test.ts | Reworks tests to validate _buildAuthAttempts ordering and makeAuthHandler iteration/filters. |
| eslint.config.js | Allows importing ssh2 by adding it to the node-modules allow list. |
Copilot's findings
- Files reviewed: 3/3 changed files
- Comments generated: 3
… KeyFile fail-fast - _connectSSH: when agentForward is enabled, also set connectConfig.agent to SSH_AUTH_SOCK so ssh2 actually has a socket to forward to. Warn when forwarding is requested without an agent available. - makeAuthHandler: map 'agent' to 'publickey' for the methodsLeft filter, since SSH servers advertise 'publickey' (agent is just a publickey-flavored method at the protocol level). Tightened types to ssh2's AuthenticationType / AnyAuthMethod so this is enforced by the compiler. - _buildAuthAttempts (KeyFile mode): fail fast with a localized error if privateKeyPath is missing or unreadable, instead of silently falling through to a generic auth failure. - Added 3 unit tests covering the new behaviors. (Written by Copilot)
zhichli
approved these changes
Apr 23, 2026
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.
Switch SSH auth in
SSHRemoteAgentHostMainServiceto ssh2'sauthHandlercallback, walking an ordered queue of attempts:privateKeyPath(if set)SSH_AUTH_SOCKis set)~/.ssh/id_ed25519,id_rsa,id_ecdsa,id_dsa,id_xmss), deduped against the explicit keyThis mirrors OpenSSH client behavior: a host that accepts
~/.ssh/id_rsastill connects when the agent is running but doesn't have the key loaded — without needing an explicit `IdentityFile` entry in `~/.ssh/config`.Other changes
Manual smoke (TODO before merging)
(Written by Copilot)