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

Bug: completions from known_hosts for ssh and ping on non-default port #175

Closed
maximunited opened this issue May 31, 2023 · 5 comments
Closed

Comments

@maximunited
Copy link

Entries of non-default ports in .ssh/known_hosts are saved as:

[192.168.1.222]:26 ssh-rsa <really-long-string-here>

When using ping or ssh completions, they are shown as:
ssh [192.168.1.222 and ping [192.168.1.222

@chrisant996
Copy link
Collaborator

chrisant996 commented May 31, 2023

Ok, thanks, I understand that the behavior isn't what you want.

Please also describe the behavior that you do want. 🙂

  • [192.168.1.222]:26
  • [192.168.1.222]
  • 192.168.1.222
  • Something else?

Also, should ssh and ping completions be different?

Also, sharing sample .ssh/config and .ssh/known_hosts files could help.

I've never used ssh, and my config and known_hosts files are empty -- so I have no first-hand knowledge to help me understand what behavior is expected. I inherited most of these completion scripts. I am happy to maintain them, but for some of them I'm learning as I go. I will try to find documentation about the file formats, but some samples would be useful.

@maximunited
Copy link
Author

maximunited commented May 31, 2023

For ssh, if the port is non default, I think it should suggest -p <port_num> from the relevant line in known_hosts
eg. ssh 19<tab> would suggest ssh 192.168.1.222 -p 26

Sample known_hosts:

100.73.210.153 ecdsa-sha2-nistp256 <long-string-cccc>
10.5.180.21 ssh-rsa <long-string-aaaaa>
dub ssh-ed25519 <long-string-bbbbb>
[192.168.1.122]:26 ssh-dss <long-string-dddd>

Sample .ssh/config file:

Host *
#       Cipher arcfour
#       Cipher blowfish-cbc
#       Cipher                  aes128-ctr
        PubkeyAcceptedKeyTypes ssh-dss*,ssh-rsa*
        StrictHostKeyChecking no
#############
### Test ###
#############
Host *.cla.nnet.net ode je jer mosc mos la lo ma mad praj esz mex 10.5.152.11 10.75.238.66 10.4.165.225 10.5.216.11 10.5.223.11 10.5.226.11 10.39.215.5 10.4.168.97 10.5.197.11 10.5.225.11 10.75.239.194 10.75.10.11 10.75.10.34 10.75.11.66 10.94.15.67 10.75.13.2 10.75.13.11 10.75.13.34 10.55.61.4 10.75.225.98 10.41.33.1 10.104.213.65 10.75.11.66 10.5.151.4 10.104.231.1 10.104.229.131 10.75.13.130 10.94.242.197 10.104.235.20 10.94.44.135 10.11.250.226 10.40.6.10 10.11.219.2 10.5.214.11
        StrictHostKeyChecking   no
        User                    root
        Port                    22
        ForwardX11              no
        ServerAliveInterval     120
        IdentityFile            ~/.ssh/id_rsa_foo

Host  mgmt*.foo.bar.com inte* gen3* MN*.xiv Gen3* Gen4* gen4* ba-* 60*.hhh.foo.com 60*.hhh 10.10.* 10.15.* 10.150.* mgmt* qa* mn* 600* 10.148.* 131* gen3* host* lsihost* 782*.hhh 9.151.184.*  9.151.182.247 9.151.182.248 9.151.182.249 9.151.182.250 9.151.182.251 9.151.182.252 xiv05a 9.151.180.142 9.151.180.143 nas6b 9.151.183.129 9.151.183.130 9.151.183.140 9.151.183.141 9.151.183.142 9.151.239.* 9.151.157.78 9.151.153.209 9.151.154.130 9.151.156.48 9.151.156.47 9.151.191.193 9.151.191.194 9.151.191.215 9.151.191.216 9.151.191.217 9.151.154.129
        User                    root
        StrictHostKeyChecking   no
        IdentityFile            ~/.ssh/id_rsa.devel
        ForwardX11              no
#       Cipher                  blowfish-cbc
#       IdentityFile            ~/.ssh/id_rsa

Host github.com
        HostName github.com
        User git
        IdentityFile ~/.ssh/github_rsa

@chrisant996
Copy link
Collaborator

chrisant996 commented Jun 1, 2023

The ssh completions include only the first host in each host definition line in the .ssh/config file. (after ignoring wildcards, etc)

image

Shouldn't it include all hosts in each host definition list in the .ssh/config file? (after ignoring wildcards, etc)
Commit 21464d1 appears to have accidentally broken that as a side effect of the refactoring that was done.

Here is the completion list if it instead includes all the known hosts:

image

I plan to make it list all the known hosts.
But since you use ssh, do you have a preference whether it should list all known hosts, or only the first entry from each host definition line?

P.S. Would it be preferable to list alphanumeric names before numeric IP addresses?

@maximunited
Copy link
Author

Yeah, I'd want to have all.
Right now if I do ssh <tab><tab> it shows:

> ssh 
Display all 1010 possibilities? (y or n)

I guess I have a lot of saved IPs and names.

P.S. Would it be preferable to list alphanumeric names before numeric IP addresses?
No preference. Any order would be good.

P.S. Why is it showing different colors in your example?

@chrisant996
Copy link
Collaborator

Yeah, I'd want to have all. Right now if I do ssh <tab><tab> it shows:

> ssh 
Display all 1010 possibilities? (y or n)

I guess I have a lot of saved IPs and names.

Cool! Done.

P.S. Would it be preferable to list alphanumeric names before numeric IP addresses?
No preference. Any order would be good.

Cool, I'll leave it as-is.

P.S. Why is it showing different colors in your example?

I made it use the "alias" match type for addresses from .ssh/config (uses the color.alias setting, blue-ish in the screenshot), and use the "cmd" match type for addresses from .ssh/known_hosts (uses the color.cmd setting, bright white in the screenshot).

(And for ping addresses from the hosts file use the default terminal color.)

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

No branches or pull requests

2 participants