13

Very newbie question!

I'm sshing to two different servers, both part of the same Amazon AWS cluster. They're not run by me.

On one ssh session, the terminal lets me autocomplete. On the other session, it doesn't - I wish it did.

Why is this - is it an option set by the server administrator?

And can I do anything about it?

thanks!

0

4 Answers 4

19

This isn't really a programming question, but it has to do with your shell. You can try starting the bash shell (by typing bash at the prompt) and see if you can autocomplete.

If that works you can use which bash to verify it's location and then chsh -s /bin/bash to set your shell permanently.

A list of available shells can also be found in /etc/shells.

1
  • I can't change my shell for some reason. Is there way to do it as root? You may not change the shell for 'counterstrike'. Apr 28, 2020 at 21:15
4

It is a combination of the shell that is being used in your ssh session as well as it's configuration.

While your shell may support autocompletion it may not be configured for it. If you're using the bash shell, you can edit your local .bashrc file for the following to provide autocomplete.

# enable bash completion in interactive shells
if [ -f /etc/bash_completion ]; then
    . /etc/bash_completion
fi
1
  • 1
    The bash completion package is only needed for more advanced completion of things like command line options, server names, VCS repository directories, ... . Completion of commands, directories, file names, variables and user names works without it.
    – ak2
    Oct 30, 2010 at 8:52
3

Copied from my own answer on unix.SE:

It seems that specifically in Ubuntu the entries in ~/.ssh/known_hosts are hashed, so SSH completion cannot read them. This is a feature, not a bug. Even by adding HashKnownHosts no to ~/.ssh/config and /etc/ssh/ssh_config I was unable to prevent the host hashing.

However, the hosts that I am interested in are also found in ~/.ssh/config. Here is a script for Bash Completion that reads the entries from that file:

_ssh() 
{
    local cur prev opts
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    prev="${COMP_WORDS[COMP_CWORD-1]}"
    opts=$(grep '^Host' ~/.ssh/config | awk '{print $2}')

    COMPREPLY=( $(compgen -W "$opts" -- ${cur}) )
    return 0
}
complete -F _ssh ssh

Put that script in /etc/bash_completion.d/ssh and then source it with the following command:

$ . /etc/bash_completion.d/ssh

I found this guide invaluable and I would not have been able to script this without it. Thank you Steve Kemp for writing that terrific guide!

1

IIRC it could also be an issue that ssh hashes the hostnames in ~/.ssh/known_hosts

most installations I know use ~/.ssh/known_hosts as source for the list of available hosts for completion but some systems also started to set "HashKnownHosts yes", which prohibits using known_hosts as a source....

if your known hosts lines start with something like

|1|BWO5qDxk/cFH0wa05JLdHn+j6xQ=|rXQvIxh5cDD3C4

then hashing is activated.

You must log in to answer this question.