I'm doing some work where I need to pivot off a machine using proxychains so I'm connecting to a system and binding a local port like so...

ssh -f -N -D 9000 [email protected]

… which returns me back to my command prompt after opening the connection. I can then use something like proxychains to run commands through host.com.

My question is: How can I connect/interact with that same session so I can get a remote shell on host.com? The way I'm doing it now is opening up another ssh session with a simple ssh [email protected], but I'm thinking there has to be a way to just utilize that first session that I opened.

2 Answers 2


If it wasn't created with multiplex enabled, you cannot.

Next time, start the background session like this:

ssh -f -N -M -S ~/.ssh/[email protected] -D 9000 [email protected]

Here -M enables multiplex master mode, and -S sets the socket path.

Now you can use ssh -S ~/.ssh/[email protected] dummyhost to open a second session over the same connection. It's possible to control the master by giving -O exit, -O check, and various other options. (Sadly, -O forward is a very recent addition.)

To make this automatic, you can use the following options in .ssh/config:

Host *
    ControlPath ~/.ssh/S.%l.%r@%h:%p
    ControlMaster auto
    ControlPersist 10m

Setting ControlPath means you do not need to specify -S every time.

Setting ControlMaster auto means that every new connection will automatically continue in background as a multiplex master. (Without it, you can still start new masters with ssh -fNM host).

Setting ControlPersist 10m means that the automatic masters will stick around for 10 minutes when they don't have any active sessions. (This is a recently added option.)

Note that batch transfers over a multiplex connection will cause interactive sessions to become really slow...


Leave off the -f (Background SSH) and the -N (Do not execute remote command) parameters, so use

ssh -D 9000 [email protected]

  • This is going to start another new SSH session which will also try to do port-forwarding to the local machine's port 9000. It will give a warning about being unable to bind to port 9000 if there is already another SSH session open which I believe is what the OP's use case looks like.
    – Tuxdude
    Mar 2, 2013 at 19:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .