2

I am calling ssh with the session I want to be the control master so I am using -M flag (equivalent would be having ControlMaster yes).

However, if the previous session failed and left a zombie control file then ssh will just log ControlSocket <control socket path> already exists, disabling multiplexing and still make the connection. That means the control socket actually isn't setup for latter sessions (that will be ControlMaster no).

Is there a way to instead have ssh fail if the control socket file already exists so my script can detect and report the issue? I could have the script check for the control file, but would require the script would have to assume the control path (which can be non-obvious due to settings in the ssh config like host aliases and ControlPath).

Note this question is a bit different from How to abort if ssh control socket already exists?. That question is asking about a control path file being present due to an existing control session, while this one is due to a failed previous session. We also want this session to be master so it can control the multiplexing. So simply removing -M won't solve this. Thx!

1
  • Try first with ssh -O check with the same -S (ControlPath) option you're using with -M -- you will get a different error if the file exists but ssh cannot connect to it. But better just remove it or use a unique name for the socket.
    – user313992
    Dec 7, 2021 at 17:33

0

You must log in to answer this question.

Browse other questions tagged .