To enable ssh autocompletion in Debian and Ubuntu:
sudo apt-get install bash-completion
Note that this has nothing at all to do with known_hosts hashing, contrary to what was stated above and the original question. If you wanted to autocomplete from known_hosts, then of course you would have to disable hashing, but that is strongly recommended against.
For example, I have:
Host *
HashKnownHosts yes
in my .ssh/config, and I still have ssh auto-completion working just fine against hosts listed in .ssh/config and /etc/hosts. You do need to add the host to .ssh/config as the OP stated:
Host my-awesome-host
Hostname the.real.host.name
(Or, you can add a host entry to /etc/hosts, which is another source for the Debian/Ubuntu scripts.)
Then, you can just type ssh my-awe<tab>
and it will be automagically completed. Again, this is even if you HashKnownHosts, which is highly recommended. (Note that bash completion needs to be enabled in your bash shell, and you need to specifically have those scripts installed as above for your distribution.)
Then, add these lines to your .bashrc
to enable it (requires a logout and log back in, or just a new bash
typed in to launch a new shell. (You don't need to enable if it's already enabled in /etc/bash.bashrc
and /etc/profile
sources /etc/bash.bashrc
).
if [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
This will enable ssh autocompletion (among other things!) from ~/.ssh/config
, /etc/hosts
, etc.
Note that Debian defaults to ash instead of bash. You can switch to bash easily:
sudo usermod -s /bin/bash "$USER"
(You'll need to log out and log back in for this to take effect.)
bash-completion
installed. – dotancohen Jun 10 '14 at 07:44