Skip to content

fix(config): add new hosts before a matching wildcard block - #126

Open
lord-helicon wants to merge 1 commit into
Adembc:mainfrom
lord-helicon:upstream-pr/fix-host-order
Open

lord-helicon wants to merge 1 commit into
Adembc:mainfrom
lord-helicon:upstream-pr/fix-host-order

Conversation

@lord-helicon

Copy link
Copy Markdown

New hosts were appended at the end of ~/.ssh/config, after a trailing Host *. OpenSSH uses the first value it finds for each option, so anything set under Host * (User, IdentityFile, …) silently overrode the same option on hosts added through lazyssh.

For example, with this config:

Host *
    User wildcard
Host b
    User me

ssh -G b resolves user wildcard. After this change the new host is written before Host *, and ssh -G b resolves user me.

New hosts are now inserted before the first Host block whose patterns match the new alias, such as Host * or Host lab-* when adding lab-3. Global settings at the top of the file (Include, options before the first Host) stay where they are. If nothing matches, the host is appended as before.

Testing

  • TestAddServerInsertsBeforeMatchingWildcard covers a trailing Host * with global Include lines and a matching pattern (lab-*). It compares the full file contents.
  • make build (gofumpt, vet, golangci-lint) and make test pass.

This PR is independent of my other two config fixes. The small helpers_test.go is identical in all three, so they merge cleanly in any order.

New hosts were appended to the end of the file, after a trailing
"Host *". OpenSSH uses the first value it finds for each option, so
anything set under "Host *" (User, IdentityFile, ...) silently
overrode the same option on the new host. Insert the new host before
the first non-global Host block whose patterns match its alias.
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.

1 participant