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?


migrated from stackoverflow.com Oct 30 '10 at 0:11

This question came from our site for professional and enthusiast programmers.


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.


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
  • 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 '10 at 8:52

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:

    local cur prev opts
    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!


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


then hashing is activated.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy