Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I remote copied a file to my laptop using:

scp someFile USER@192.168.178.32:/home/USER/put/it/some/where/oh/damn/you/here

I want to be able to autocomplete the remote path by hitting tab.

share|improve this question
1  
It's enabled for rsync, which in my opinion is far superior to scp –  Marco Ceppi Mar 3 '12 at 17:36
2  
It's enabled by default in zsh. –  Stéphane Gimenez Mar 3 '12 at 18:17
3  
It's enabled for scp also, al least it works here. You need an ssh-key already added to an ssh-agent. –  enzotib Mar 3 '12 at 20:56

3 Answers 3

up vote 13 down vote accepted

Make sure that you've turned on the fancy autocompletion. On many distributions, this means your ~/.bashrc needs to contain . /etc/bash_completion.

You'll need to have passwordless authentication set up, i.e. with a key that's already loaded in ssh-agent.

Establishing an SSH connection is slow, so you can considerably speed up completions by establishing a connection once and for all and using that connection thereafter. The relatively complicated way to do that is to open a master SSH connection with ssh -N -M target-host after setting up master-slave connections in ~/.ssh/config; see Multiple ssh sessions in single command for instructions (you need the ControlMaster and ControlPath options).

The simple method is to mount the remote filesystem over SSHFS and use cp with normal shell completion.

mkdir ~/remote
sshfs USER@192.168.178.32:/home/USER ~/remote
cp -p someFile ~/remote/put/it/some/where/oh/damn/you/here
share|improve this answer
    
It looks like there is something in /etc/bash_completion to source ~/.bash_completion. I want to be able to have this feature on a remote server where I can't write to /etc/ and there is no /etc/bash_completion (though there is /etc/bash_completion.d/. Is there a version that would be safe to run from my home directory? There's at least one reference to ~/.bash_completion so I'm afraid there is more I'm missing and there could be a cyclical loop or something else that might cause errors. –  redEvo Nov 13 '12 at 23:28

All I needed to do was to add my public key to the remote machine:

cat ~/.ssh/id_rsa.pub | ssh USER@192.168.178.32 "cat - >> ~/.ssh/authorized_keys"

And now scp tab-completes.

Look here if you need to set up your keys first.

share|improve this answer
3  
This is what ssh-copy-id is for, plus it will handle the file permissions for you. –  glenn jackman Jul 7 '13 at 12:52

You could switch to lftp instead of using scp. It gives you a nice consistent interface for file transfer over ftp, sftp and ssh including the autocomplete you are looking for and more (i.e. wildcards).

lftp fish://user@machine

opens a connection over ssh like you do above with scp. Many machines support sftp:// too which is even nicer in my experience.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.