Skip to content

fix: pass custom -c config to ssh via -F - #159

Open
vulragrag-star wants to merge 1 commit into
quantumsheep:masterfrom
vulragrag-star:fix/106-config-pass-f-to-ssh
Open

vulragrag-star wants to merge 1 commit into
quantumsheep:masterfrom
vulragrag-star:fix/106-config-pass-f-to-ssh

Conversation

@vulragrag-star

Copy link
Copy Markdown

Summary

When sshs is started with a custom -c/--config file, Host aliases from that file were listed in the UI but the default connect command was still ssh "{{{name}}}". OpenSSH then looked only at the usual system/user configs, so aliases that only exist in the custom file failed to resolve (Could not resolve hostname / hostname contains invalid characters for quoted names).

If the user left the default command template alone, build ssh -F <config> "{{{name}}}" instead so the same file used to populate the list is also passed to ssh. An explicit -t/--template is left unchanged. OpenSSH accepts a single -F; when several custom paths are given, the last non-system path is used.

Fixes #106.

Test plan

  • cargo test --bin sshs tests::
    • default configs keep the default template
    • custom -c injects -F
    • paths with spaces are shell-quoted
    • explicit -t is left alone
    • multiple custom configs use the last non-system path

@Arnaudmyges

Copy link
Copy Markdown

Thanks for this, #106 is a real pain point. One use case this would break, though: using -c on a fragment that ~/.ssh/config already includes.

I split my hosts by context and use -c only to filter the list:

# ~/.ssh/config
Include config.d/*.conf        # personal.conf, work.conf (work hosts carry `Tag work`)

Match tagged work
  IdentityFile ~/.ssh/id_work
  IdentitiesOnly yes
sshs -c ~/.ssh/config.d/work.conf

Today this works: ssh "host" reads ~/.ssh/config, so the Match/Host * blocks apply. With -F work.conf, OpenSSH skips ~/.ssh/config entirely, so those blocks are gone. Quick check with ssh -G:

$ ssh -G -F ~/.ssh/config demo | grep -E '^identit'     # current behaviour
identitiesonly yes
identityfile ~/.ssh/id_work
$ ssh -G -F work.conf demo | grep -E '^identit'         # with this PR
identitiesonly no
identityfile ~/.ssh/id_rsa
identityfile ~/.ssh/id_ed25519
...

The host still connects, but with the wrong keys offered, silently, which is the kind of thing IdentitiesOnly is there to prevent.

Since sshs already follows Include, maybe -F could be added only when the custom file is not reachable from ~/.ssh/config (or behind an opt-in flag)? Users in my situation can pin -t 'ssh "{{{name}}}"', but it would be nice not to need it.

When -c/--config points at a non-default file and the default command
template is used, inject ssh -F so Host aliases (and HostName/User/Port)
from that file still resolve. Fixes connecting via aliases that only
exist in the custom config (issue quantumsheep#106).
@vulragrag-star
vulragrag-star force-pushed the fix/106-config-pass-f-to-ssh branch from ca40e8f to 7fe90cd Compare October 26, 2026 00:44
@vulragrag-star

Copy link
Copy Markdown
Author

Good catch, thanks. -F is now skipped when the file is already read by plain ssh (a default config or Included from one, outside Match), so sshs -c ~/.ssh/config.d/work.conf keeps ssh "{{{name}}}"; added tests.
Tip: 7fe90cd0fb1a4e2fa54b53e2def6a3682994a79b.

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.

Connecting to Host "My Server" fails from non-default location config

2 participants