1

I'm trying to create multiplexed ssh connections for a series of commands that run in succession, then after the series of commands is finished, close the multiplex session.

According to the documentation, the first connection should start the control master:

ssh -o "ControlMaster=auto" -S /home/justin/.ssh/sockets/multiplex_ssh.sock [email protected] "uptime"

Then the rest of the commands just need to pass:

ssh -S /home/justin/.ssh/sockets/multiplex_ssh.sock [email protected] "free -m"
ssh -S /home/justin/.ssh/sockets/multiplex_ssh.sock [email protected] "hostname"
ssh -S /home/justin/.ssh/sockets/multiplex_ssh.sock [email protected] "date"

Finally, to close the multiplex ssh session, I should be able to do:

ssh -O exit -S /home/justin/.ssh/sockets/multiplex_ssh.sock [email protected]

Unfortunately, the first ssh command running ControlMaster=auto does not keep a socket active in the directory /home/justin/.ssh/sockets when passing a command to ssh. It instead immediately closes the socket.

How is this possible?

1 Answer 1

4

It looks like you forgot to set ControlPersist. If not set, then the master connection will not remain open if that first session is closed.

For example you can set in your $HOME/.ssh/config:

ControlPersist 600
3
  • I can't use a ssh config file, I have to specify this on the command line arguments to ssh. I don't know a given amount of time, should I just set the time to like 1 hour, and then do the exit at the end?
    – Justin
    Aug 3, 2015 at 1:46
  • 1
    I can use ControlPersist yes
    – Justin
    Aug 3, 2015 at 1:48
  • That should be fine, I think. Aug 3, 2015 at 1:49

You must log in to answer this question.

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