8

This question already has an answer here:

I have a script which runs several commands remotely through ssh. I'm running each command separately because I want to do other things in between executions.

However, I don't want to recreate an ssh session every time I issue a new command. I've read about -oControlMaster but I can't seem to get it to work.

When I run:

ssh -oControlMaster=yes -oControlPath=/tmp/test.sock root@host

after I enter my password, I just get an ssh session. If I exit out, the /tmp/test.sock file is no where to be found.

What am I missing?

marked as duplicate by Archemar, vonbrand, Community Nov 22 '15 at 20:21

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

12

You can use the ControlPersist option to leave the socket after you disconnect from the server.

e.g in my ssh config file i have this snippet, which leave the connection open 3 sec.

Host *
   ControlMaster auto
   ControlPath ~/.ssh/master-socket/%r@%h:%p
   #ControlPath ~/.ssh/%r@%h:%p
   ControlPersist 3s
0

One master connection needs to be open for a second connection to be able to use the master connection.

The socket file is only available while the master connection is open. If you close the master connection then the socket file is removed. Any open "slave connection" will also be closed if the master connection is closed.

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