Ubuntu and Debian to my knowledge bring with the bash-completion
package exactly the functionality that you ask. However if the remote server has a scheme implemented to thwart break-in attempts (e.g. by limiting the number of connections within a given time interval and blocking if a client exceeds it) you will run into problems.
Check /etc/bash_completion
on your system and /etc/bash_completion.d/ssh
. If it doesn't exist, make sure to apt-get install bash-completion
. Once that's done, make sure that your .bashrc
or .profile
loads that global auto-completion file.
This brings usually functionality to both auto-complete the remote hostname from your $HOME/.ssh/known_hosts
(grep _known_hosts_real /etc/bash_completion
) and auto-completion for remote folders on scp
.
One note of caution: if the remote host outputs extra stuff upon login, the auto-completion tends to break. One way to work around this can be (but I found this not to work everywhere) to bail out without any output on the remote machine:
[ -z "$SSH_TTY" ] && exit
... i.e. show no banner or so. You include this line in /etc/sshd/sshrc
on the remote box or at the top (below hashbang) of whatever script you are executing to show the ASCII art form of the fingerprint. Note that the above line is bourne-shell syntax, adjust it of needed. It checks whether the SSH_TTY
env. variable is empty and if so exits with exit code 0.
sshd
.