8

I'm wondering if I already have an established SSH tunnel and I want to minimize re-authenticating with an ssh server for each task, is there a way to use an existing tunnel to pull a file from the SSH server using SCP on the local machine without re-authenticating?

I'm trying to avoid using ssh keys, I'd just like to minimize the amount of times a password needs to be entered for a bash script.

ssh -t user@build_server "*creates a build file...*"

Once that command is completed there is a file that exists on build_server. So if the above tunnel was still open, is there way to use that tunnel from my LOCAL machine to run SCP to and bring the file to the local machines desktop?

nullByteMe
  • 6,141
  • 13
  • 62
  • 99

1 Answers1

12

Yes, session sharing is possible: man ssh_config and search for ControlMaster and/or check here and here. Is this what you are looking for?

Adrian Frühwirth
  • 42,970
  • 10
  • 60
  • 71
  • 1
    Note that if you need to scp over that control master, you have to use a -o option like `scp -o "ControlPath=$SSH_CONTROL_SOCKET" root@"$ONE_HOST":/etc/hosts .` to make use of the multiplexed connection (unlike ssh -S). See https://superuser.com/questions/1299180/cannot-scp-over-a-shared-connection – labyrinth Aug 18 '20 at 21:04