I have two servers running Centos 7 that communicate with each other. In a shell script, I need to stop my custom services running on the other node via ssh. The problem is that occasionally the entire ssh session is closed with the exit code 255. I do not have any explanation and cannot even recreate a similar situation to investigate more. I would appreciate any helpful ideas.


[root@server1 ~]# ssh server2
[root@server2 ~]# ssh -vvv -tt server1 "systemctl stop myservice"
OpenSSH_7.4p1, OpenSSL 1.0.2k-fips  26 Jan 2017
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 58: Applying options for server1
debug1: auto-mux: Trying existing master
debug2: fd 3 setting O_NONBLOCK
debug2: mux_client_hello_exchange: master version 4
debug3: mux_client_forwards: request forwardings: 0 local, 0 remote
debug3: mux_client_request_session: entering
debug3: mux_client_request_alive: entering
debug3: mux_client_request_alive: done pid = 5429
debug3: mux_client_request_session: session request sent
debug1: mux_client_request_session: master session id: 2
debug3: mux_client_read_packet: read header failed: Broken pipe
debug2: Control master terminated unexpectedly
Shared connection to server2 closed.
[root@server1 ~]# echo $?

Addition details:
ControlPersist 60s
ConnectTimeout = 1
ControlPath /dev/shm/%r@%h:%p
StrictHostKeyChecking no

I realized that the ssh -vvv -tt server1 "systemctl stop myservice" command doesn't get any error or non-zero exit code. But the problem is that because of this command, the ssh connection from server 1 to server 2 breaks.

  • Is there a chance that the myservice service on server1 was running a ssh connection to server2? If it was, then your interactive session re-used it, and systemd killed it. I’d suggest you consider trying not using the controlmaster=auto configuration. Commented Nov 29, 2023 at 8:31

1 Answer 1


perhaps increasing the maximum waiting time before the timeout occurs could be a viable option.

  • Thanks for your reply. The response time to the request is less than 10 seconds. Commented Nov 28, 2023 at 10:51

You must log in to answer this question.

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