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?

  • Please show us the commands you are running. – Iain Feb 20 '16 at 16:32
  • 2
    Probably you can use ControlMaster/ControlPath options in ~/.ssh/config for that particular CentOS server. – ALex_hha Feb 20 '16 at 16:35
  • @iain Im using 'scp -Cp /path/to/local_file user@host:remote/path/' – Ameer Elsherif Feb 20 '16 at 17:17

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.

  • 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

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

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