Mailing List Archive

Another question about this shell magic...
Hi list,

what confuses me a bit is this shell(?) magic: When I type 'ssh ' on my console an hit the TAB twice, I get a list of host I would probably ssh to. This list does not come from an element in my bash history. On my initial question, I guessed this would somehow come from the known_hosts file. Does it?
Can someone tell how this magic works?

Thanks, Martin
Re: Another question about this shell magic... [ In reply to ]
Hi Martin,

Martin Drescher wrote on Thu, Oct 01, 2020 at 02:06:22PM +0200:

> Can someone tell how this magic works?

No, and this question is off-topic on this list because it is not
related to OpenSSH. It is a question about your shell, and about
how the configuration of your shell works, and you don't even provide
information about how you have configured your shell.

Yours,
Ingo
_______________________________________________
openssh-unix-dev mailing list
openssh-unix-dev@mindrot.org
https://lists.mindrot.org/mailman/listinfo/openssh-unix-dev
Re: Another question about this shell magic... [ In reply to ]
check the shell’s configuration and plugins w.r.t. tab completion
(I know at least there is a ZSH plugin doing that for me in the Oh-My-Zsh templates)

> On 01 Oct 2020, at 14:06 , Martin Drescher <drescher@snafu.de> wrote:
>
> Signed PGP part
> Hi list,
>
> what confuses me a bit is this shell(?) magic: When I type 'ssh ' on my console an hit the TAB twice, I get a list of host I would probably ssh to. This list does not come from an element in my bash history. On my initial question, I guessed this would somehow come from the known_hosts file. Does it?
> Can someone tell how this magic works?
>
> Thanks, Martin
>
>
>
Re: Another question about this shell magic... [ In reply to ]
On 01/10/2020 13:06, Martin Drescher wrote:
> what confuses me a bit is this shell(?) magic: When I type 'ssh ' on my console an hit the TAB twice, I get a list of host I would probably ssh to. This list does not come from an element in my bash history. On my initial question, I guessed this would somehow come from the known_hosts file. Does it?
> Can someone tell how this magic works?

Under Ubuntu 18.04, it appears to be giving me everything in /etc/hosts
*and* everything in ~/.ssh/known_hosts

For the magic see:

/usr/share/bash-completion/completions/ssh

/usr/share/bash-completion/bash_completion   # function _known_hosts_real()

_______________________________________________
openssh-unix-dev mailing list
openssh-unix-dev@mindrot.org
https://lists.mindrot.org/mailman/listinfo/openssh-unix-dev
Re: Another question about this shell magic... [ In reply to ]
On 01.10.20 14:25, Brian Candler wrote:
> On 01/10/2020 13:06, Martin Drescher wrote:
>> what confuses me a bit is this shell(?) magic: When I type 'ssh ' on my console an hit the TAB twice, I get a list of host I would probably ssh to. This list does not come from an element in my bash history. On my initial question, I guessed this would somehow come from the known_hosts file. Does it?
>> Can someone tell how this magic works?
>
> Under Ubuntu 18.04, it appears to be giving me everything in /etc/hosts *and* everything in ~/.ssh/known_hosts
>
> For the magic see:
>
> /usr/share/bash-completion/completions/ssh
>
> /usr/share/bash-completion/bash_completion   # function _known_hosts_real()

Oh, ok, I see there is no real magic. There are some hosts in my known_hosts, which have not been hashed. How this would happen, I don't know.


Thanks, pointing me to function _known_hosts_real() did the trick.


--

Martin
Re: Another question about this shell magic... [ In reply to ]
On Thu, 1 Oct 2020, Ingo Schwarze wrote:

> Hi Martin,
>
> Martin Drescher wrote on Thu, Oct 01, 2020 at 02:06:22PM +0200:
>
> > Can someone tell how this magic works?
>
> No, and this question is off-topic on this list because it is not
> related to OpenSSH.

It's most definitely related to OpenSSH, specifically how the shell
interacts with it.

In answer to the question: many operating system distributions
(especially Linux) have configured their shells with tab-completion
helpers that are contextually invoked by the shell after specific
commands. Another example of this might be "git <tab>" returning a list
of git subcommands.

In this case, the helper is probably looking at the contents of your
~/.ssh/known_hosts or, with less likelihood, ~/.ssh/config's Host/Match
configuration. I don't mind these, though they can be pretty brittle in
the face of ssh_config aliases and HashKnownHosts settings, etc.

Some shell configurations go further and will configure tab-expansion
helpers for things like scp remote paths, e.g. "scp host:foo<tab>" will
actually ssh to the remote host, run "ls foo*" and use the result to
offer a set of completions.

I don't like these because they implicitly perform heavy-weight
operations (establishing a connection to a remote host) without the
user really knowing what's going on. Note that, depending on your
configuration, establishing such a connection can have significant
security consequences - e.g. consider agent-forwarding.

Anyway, check your shell configuration. On many Linux distributions, you
might want to start with /etc/bash_completion*

-d
_______________________________________________
openssh-unix-dev mailing list
openssh-unix-dev@mindrot.org
https://lists.mindrot.org/mailman/listinfo/openssh-unix-dev
Re: Another question about this shell magic... [ In reply to ]
On 10/2/20 5:46 AM, Damien Miller wrote:
[snip]
> In this case, the helper is probably looking at the contents of your
> ~/.ssh/known_hosts or, with less likelihood, ~/.ssh/config's
> Host/Match configuration. I don't mind these, though they can be
> pretty brittle in the face of ssh_config aliases and HashKnownHosts
> settings, etc.
[snip]

In the case of zsh [1] and its tab completion for tools in the OpenSSH
suite, it seems to be looking at both known_hosts and ssh_config among
other things, but only the local versions not the global versions. It
can take guesses at account names and not just host names.

/Lars

[1] http://zsh.sourceforge.net/

git clone git://git.code.sf.net/p/zsh/code

See: ./code/Completion/Unix/Command/_ssh
_______________________________________________
openssh-unix-dev mailing list
openssh-unix-dev@mindrot.org
https://lists.mindrot.org/mailman/listinfo/openssh-unix-dev