Skip to content

Fix SSH config parsing failure when Match directive precedes Host blocks#212

Draft
Copilot wants to merge 2 commits into
mainfrom
copilot/fix-ssh-config-match-directive
Draft

Fix SSH config parsing failure when Match directive precedes Host blocks#212
Copilot wants to merge 2 commits into
mainfrom
copilot/fix-ssh-config-match-directive

Conversation

Copilot AI commented May 2, 2026

Copy link
Copy Markdown
Contributor

russh-config does not support the Match keyword — encountering it before the first Host block causes the parser to return HostNotFound, making sshping fail entirely. Moving Match directives to the end of the file was the only workaround.

Changes

  • strip_match_blocks(contents: &str) -> String — preprocesses raw SSH config content by dropping every Match line and all option lines belonging to that block (up to the next Host or Match keyword). Comments and blank lines inside Match blocks are also dropped.
  • parse_config_path(path, host, context) — wraps file reading + strip_match_blocks + russh_config::parse(). Replaces all three parse_path() call-sites (main config, jump host config, ProxyCommand config).

Example config that previously failed

Match host * exec "gpg-connect-agent UPDATESTARTUPTTY /bye"

Host myserver
    User alice
    Port 2222

The Match block and its settings are stripped before being handed to russh-config, leaving valid Host-only content to parse.

@codacy-production

codacy-production Bot commented May 2, 2026

Copy link
Copy Markdown

Not up to standards ⛔

🔴 Issues 2 medium

Alerts:
⚠ 2 issues (≤ 0 issues of at least minor severity)

Results:
2 new issues

Category Results
Complexity 2 medium

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

Agent-Logs-Url: https://github.com/TeddyHuang-00/sshping/sessions/dd3825c9-df43-4ee0-8990-76cf24cdf732

Co-authored-by: TeddyHuang-00 <64199650+TeddyHuang-00@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix ssh configuration parsing error with Match directive Fix SSH config parsing failure when Match directive precedes Host blocks May 2, 2026
Copilot AI requested a review from TeddyHuang-00 May 2, 2026 23:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

can't find hosts with Match directive at start of ssh_config

2 participants