3

I'm using the scp command to copy files from my local machine (ArchLinux) to my server (CentOS 6.5).

But for each scp command a new connection is established and although I'm using SSH keys for authentication the proccess is taking to much time.

So, is there any way to maintain the connection and make multiple transfers over it?

1 Answers1

5

Nobody took the opportunity to complete answer and I didn't find any duplicate, so here we go.

You can set up ~/.ssh/config, with these options:

Host machine1
  HostName machine1.example.org
  User yourusername
  IdentityFile ~/.ssh/id_rsa-something
  ControlPath ~/.ssh/controlmasters/%r@%h:%p
  ControlMaster auto
  ControlPersist 10m

Then make sure you mkdir ~/.ssh/controlmasters/ and from that time, your connections to machine1 will persist for 10 minutes so you can issue more sessions or data transfers during one connection.

Jakuje
  • 9,715
  • 2
  • 42
  • 45
  • Can you please explain what exactly will this do? I mean what is ControlMatser and ControlPath? And is it possible to make the connection presist for undefined period and then close it manually? Finally, Do I add these lines to the local or remote machine? – Ameer Elsherif Feb 20 '16 at 17:18
  • The options are described well in manual page (`man ssh_config`). It is local configuration (server has to support it, but openssh shipped nowadays do). Yes, you can set up infinite time (`Yes` value) and close it using `ssh -O exit machine1`. – Jakuje Feb 20 '16 at 17:21
  • You are welcome. Glad to help. – Jakuje Feb 20 '16 at 22:03