Is there a way to keep ssh authentication open for several scp commands?

3

I need to copy several small files from a remote machine to a local one. I need to do this several times a day. Currently, I use a script that use scp to copy the files. However, this is slow as every time, I need to authenticate. Is there a way, beside mounting, to do one authentication and keep it alive until I finish the copy?

Yotam

Posted 2013-02-11T08:19:03.323

Reputation: 559

why not copy the individual files into a folder, zip and then send it across in one go? – Jay – 2013-02-11T08:24:08.483

They are scatter over several folders on a computation cluster which I don't wish to run script on. I guess that this is an option con consider though. – Yotam – 2013-02-11T08:26:55.430

Answers

1

Just use the ControlMaster feature of SSH. For this purpose I placed a global Option:

Host *
    ControlPath ~<user>/.ssh/ctrl-%r-%h-%p

In my .ssh/config. Of course you must replace <user> accordingly by your login name.

Whenever I want to setup an initial master connection I add '-M':

ssh -M <machine>

This creates a control socket with a filename specified above. Any subsequent call to ssh/scp targeting that <machine> will reuse the existing master connection. Dramatically speeding up the connection process because no further authentication is needed for the time the control (==master) connection exists. As a pleasant side effect you don't need to re-enter your pass-phrase once you give it for establishing the master connect.

sparkie

Posted 2013-02-11T08:19:03.323

Reputation: 2 110

0

You can use ssh-add to add private keys to your ssh authentication agent. See

man ssh-add

and

man ssh-agent

user570500

Posted 2013-02-11T08:19:03.323

Reputation: 606