scp
isn't very smart: when given multiple command line arguments that are files from the same remote host, it opens a new connection for each argument.
You can use rsync
instead of scp
, it's smarter this way (and in other ways).
rsync -r -e 'ssh -P PORT' user@host:/home/user/something/{file1,folder1,folder2,folder3,folder4} folder/folder2/
Another approach is to pass a single argument to scp
that describes multiple files.
A different approach is to set up your system so that you don't have to authenticate all the time. Preferably, set up key authentication, which is in most scenarios both more convenient and more secure. Alternatively, or in addition, set up connection sharing, so that you only need to authenticate once per session. In any case, set up an alias so you don't have to specify the username and port every time. In your ~/.ssh/config
:
ControlMaster auto
ControlPath ~/.ssh/control:%h:%p:%r
Host nick
HostName real-host-name.example.com
User bob
Port 1234
Run ssh -Nf nick
to open a connection, and then all subsequent connections to nick
will piggyback on the existing connection. Now you can just run
scp -r nick:/home/user/something/{file1,folder1,folder2,folder3,folder4} folder/folder2/
id.rsa
will have600
permissions by default andssh
won't even work if it doesn't. This means it is safe from anyone butroot
and nothing is really safe fromroot
, certainly not passwords. – terdon Nov 10 '14 at 16:14ssh-keygen
and 2) ssh/scp will complain and ask for a password if the file is readable by anyone else. At least on Linux anyway. – terdon Nov 10 '14 at 16:19