nullByteMe
nullByteMe

Reputation: 6391

Can I use an existing SSH connection and execute SCP over that tunnel without re-authenticating?

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?

Upvotes: 10

Views: 7973

Answers (2)

a.deshpande012
a.deshpande012

Reputation: 744

The existing answer is great, but in the interest of having an easy-to-use snippet that you can copy-paste, I'll write that here.

Copied from here, which is linked in the accepted answer, your ~/.ssh/config should look like this:

Host machine1
        HostName machine1.example.org
        User user
        ControlPath ~/.ssh/controlmasters/%r@%h:%p
        ControlMaster auto
        ControlPersist 10m

Note that you should do mkdir ~/.ssh/controlmasters beforehand.

This will make new ssh connections reuse existing connections (and authentication) instead of making you reauthenticate. Note that ControlPersist 10m means that the connection will be kept open until 10 minutes after the last ssh session closes, after which you will have to reauthenticate.

Upvotes: 2

Adrian Frühwirth
Adrian Frühwirth

Reputation: 45566

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?

Upvotes: 15

Related Questions