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

OpenSSH host-matching rules not honored #261

Closed
schemacs opened this issue Feb 6, 2014 · 2 comments
Closed

OpenSSH host-matching rules not honored #261

schemacs opened this issue Feb 6, 2014 · 2 comments

Comments

@schemacs
Copy link

schemacs commented Feb 6, 2014

I read this, says 'with more specific hostmasks taking precedence', but when I tried, the output is not what the documentation says:

>>> from paramiko.config import SSHConfig
>>> ssh_config = SSHConfig()
>>> ssh_config.parse(open('/tmp/ssh_config'))
>>> import pprint
>>> pprint.pprint(ssh_config._config)
[{'config': {}, 'host': ['*']},
 {'config': {'port': '22'}, 'host': ['*']},
 {'config': {'port': '23'}, 'host': ['*.example.com']}]
>>> ssh_config.lookup('ssh.example.com')
{'hostname': 'ssh.example.com', 'port': '22'}

In the example above, the port for ssh.example.com should be 23(the more specific one i.e. *.example.com, not *). Any one to clear out this for me? Thanks.
I read through the code, but found nothing dealing with this kind of precedence.

I first asked this question on stackoverflow.com, but someone suggest me open one issue here.
http://stackoverflow.com/questions/21567192/openssh-host-matching-rules-not-honored-in-paramiko

@lndbrg
Copy link
Contributor

lndbrg commented Feb 6, 2014

That is actually a documentation bug and not a bug in the code! The openssh_config man page states this:

For each parameter, the first obtained value will be used.
The configuration files contain sections separated by ``Host'' specifications, and that section is only
applied for hosts that match one of the patterns given in the specification.
The matched host name is the one given on the command line.

Since the first obtained value for each parameter is used, more host-specific declarations should be
given near the beginning of the file, and general defaults at the end.

And this is what we follow. In older releases of paramiko the broken behaviour described by the documentation was used. This was changed in #93 and several other pull requests after that one.

The documentation will be fixed!

@schemacs
Copy link
Author

schemacs commented Feb 6, 2014

Thanks for clear out this for me. I have sent you one pull request to fix this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants