I use the authorized-key to log into my remote ubuntu server. I need to use scp
frequently to cp files from my local machine to my remote machine. I want to enable the autocompletion as I did with my local machine by bash-autocompletion
.
How could I do that?
Updated
I tried zsh
(https://github.com/robbyrussell/oh-my-zsh), the scp
works fine with auto-completion. How could I do it with my bash
?
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 toapt-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 onscp
.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:
... 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 theSSH_TTY
env. variable is empty and if so exits with exit code 0.I guess not, since you don't have access to the remote filesystem until you actually hit enter and authenticate when you are doing SCP.
bash-autocompletion kicks in only after getting successfully logged in to remote server or after loading bash profile which sources bash-completion script in the case of local login.
you might want to look into sshfs which mounts remote filesystem locally and then you can do auto-completion on that.