Question

Why am I getting packet_write_wait: Connection to xxx.xx.xx.xxx port 22: Broken pipe?

Posted September 1, 2017 63.7k views
Linux CommandsUbuntu 16.04

Earlier I was able to ssh to my droplet using ssh root@xxx.xx.xx.xxx command. But from yesterday I am getting this error packet_write_wait: Connection to xxx.xx.xx.xxx port 22: Broken pipe. What could be the possible reason for it. And how to solve it?

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
2 answers

Hi, if you’re getting that error it means that your SSH connection was cut off due to a long period of inactivity. You can prevent that from happening by configuring either the SSH server or client to check if the other is still connected periodically.

To do so on the server, add the following two lines to /etc/ssh/sshd_config:

ClientAliveInterval 300
ClientAliveCountMax 2

On the client side, if you are using the ssh command line program, add the following lines to ~/.ssh/config. This will enable this feature for all remote hosts.

Host *
    ServerAliveInterval 300
    ServerAliveCountMax 2

Otherwise, if you’re using a GUI program, it should have a setting for Keep Alive.

This will send a ping every 300 seconds (5 minutes) and disconnect after 2 failures (in case the other side actually disconnected and isn’t simply inactive).

  • I’m having the same problem, not sure how to resolve this issue, tried the above configuration but still, the problem persists 4/10 pipeline builds, rarely it passes most of the time it was failing, here is my log

    $ ssh -v root@xxx.xxx.xxx.xx 'nohup /../../../../../../some.sh >> some_log.log &'
     OpenSSH_7.9p1 Debian-10+deb10u2, OpenSSL 1.1.1d  10 Sep 2019
     debug1: Reading configuration data /root/.ssh/config
     debug1: /root/.ssh/config line 1: Applying options for *
    .
    .
    .
    .
    .
    
     debug1: Authentication succeeded (publickey).
     Authenticated to xxx.xxx.xxx.xx ([xxx.xxx.xxx.xx]:22).
     debug1: channel 0: new [client-session]
     debug1: Requesting no-more-sessions@openssh.com
     debug1: Entering interactive session.
     debug1: pledge: network
     debug1: client_input_global_request: rtype hostkeys-00@openssh.com want_reply 0
     debug1: Remote: /root/.ssh/authorized_keys:1: key options: agent-forwarding port-forwarding pty user-rc x11-forwarding
     debug1: Remote: /root/.ssh/authorized_keys:1: key options: agent-forwarding port-forwarding pty user-rc x11-forwarding
     debug1: Sending environment.
     debug1: Sending command: nohup /../../../../../../some.sh >> some_log.log &
     debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
     debug1: client_input_channel_req: channel 0 rtype eow@openssh.com reply 0
     packet_write_wait: Connection to xxx.xxx.xxx.xx port 22: Broken pipe
    

    I’m using GitLab ci as my pipe to run this commands

    • Hi Harish Shiv Kumar,

      Is the above problem solved for you? if yes kindly advice how u were able solve it. I have a similar problem.
      SSN dipatch run fatal broken pipe: Connection to xxx.xx.xx.xxx port 22: Broken pipe

      Regards

  • Same Problem… Follow your instruction But Not Work

I ran into the problem of similar nature. I found out the problem to be sftp configuration of the server. I tried to add users with sftp access but not the ssh. Later found out that the “Match Group groupname” record in /etc/ssh/sshdconfig had some issues. My normal account was also mixed up in the ssh client list that produced ‘packetwrite_wait’ issue.

Now, I removed my normal user from the group and everything is working fine.

It might not be the same over your case but do keep in mind if your normal user (the one you try to login with ssh) is not on the groups that has limited access on the server.

This might have been solved. If above solution doesn’t work for you, try checking group and access records on your server.

Submit an Answer