Centos – How to maintain ssh connection for multiple scp transfers

arch-linuxcentosfilesscpssh

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?

Best Answer

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.