Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ssh config settings outside of a Host block show a warning and fail #6

Open
morbeo opened this issue Nov 28, 2024 · 3 comments
Open

Comments

@morbeo
Copy link

morbeo commented Nov 28, 2024

When directives are present that are outside of a Host block a warning is shown and the program exits with status code 1.
I have the following at the top of my ssh config file:

PermitLocalCommand yes
Include config.d/*

and some hosts

$ grep -c -w ^Host ~/.ssh/config
16

but I am getting the following warning unless I comment the first two settings

$ uvx --from sshclick sshc hosts
WARNING:root:Config info without Host definition on SSH-config line number 0
$ head -2 ~/.ssh/config
#PermitLocalCommand yes
#Include config.d/*

$ uvx --from sshclick sshc hosts
┌──────┬─────────┬────────┬────────────────┬────────────┐
│ name │ group   │ type   │ param:hostname │ param:user │
├──────┼─────────┼────────┼────────────────┼────────────┤
│ g    │ default │ normal │ ***            │ root       │
│ am   │ default │ normal │ ***            │ root       │
...
@karlot
Copy link
Owner

karlot commented Nov 28, 2024

Hi,
In your case, here we have basically 2 different issues.

  1. Handling of global keywords (PermitLocalCommand) without prior definition of Host xxxx

From what I understand, if this is defined like that, it is applied for all hosts that are defined below this line, unless of course more specific Host definition is matches by "pattern" or explicit name/fqdn, and that one specifically overrides the argument.

This can be also achieved same way by defining it like this at the top of the ssh config:

Host *
    PermitLocalCommand yes
...

This would result with same behavior and sshclick will be able to parse it normally, and also when viewing host details present all those "inherited" attributes when establishing connection.
This also seems to me as more "explicit" approach in my view

Regarding support for such "host-less" config attributes, since they are supported by current clients, I will consider how to integrate that into the features for next releases...

  1. Include keyword

This one was on my radar from the beginning, and I still don't have good idea how to approach it...
It is really not a problem to follow "include" directives and slurp other config files.
Also the problem is not displaying it once it is all parsed and ready for printing or displaying in TUI mode...

For me problem is then how to optimally approach adding/editing configurations, and re-rendering configurations.
Which file should be updated, and under what rules. How to distinct what goes into what file... should it be based only on initial read? Should sshc or ssht interfaces be allowed to "move" hosts or groups between files?
I think all this is possible, but it would require a lot more code and time. :D

If you have any proposals how to approach it, I'm open for ideas and discussions.

@morbeo
Copy link
Author

morbeo commented Nov 29, 2024

I already have a generalized Host * at the bottom of the file. I was keeping this preamble for Canonicalization rules which I no longer use. You are correct that PermitLocalCommand can be moved to Host *. I would rather keep the include on top though.

On the support of includes - you already have SSH_Config to parse files. I guess they need to be loaded in some tree or DAG and make the hosts and groups aware of their own source.

@karlot
Copy link
Owner

karlot commented Nov 30, 2024

In terms of "includes" you are right, I fully support it being on top for clarity, as openssh clients (ssh, sftp, etc...) treats this keyword similary like C pre-processor... basically when this line is reached, it is during processing just replaced with content of linked files.

This makes pure ssh config very flexible in use, such as adding bunch of common Keyword/Args pairs to separate file, and then in main file use Include keyword to load common args to multiple Host definitions.

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

No branches or pull requests

2 participants