简体   繁体   中英

Write failed : broken pipe

I have a headless Ubuntu server. I ran a command on the server (snapraid sync) over SSH from my Mac. The command said it would take about 6 hrs, so I left it over night.

When I came down this morning, the Terminal on the Mac said: "Write failed: broken pipe"

I'm not sure if the command executed fully. Is this a timeout issue? If so, how can I keep the SSH connection alive overnight?

This should resolve the problem for Mac osX version: 10.8.2

add:

ServerAliveInterval 120
TCPKeepAlive no

to this file:

~/.ssh/config

Or, if you want it to be a global change in the SSH client, to this file

/private/etc/ssh_config

"ServerAliveInterval 120" basically says to "ping" the server with a NULL packet every 120s, and "TCPKeepAlive no" means to not set the SO_KEEPALIVE socket option (since you shouldn't need it with ServerAliveInterval already set, and apparently it's "spoofable" or some odd).

The servers similarly have something they could set for the same effect (ClientKeepAliveInterval) but typically you don't have control over those settings as much.

You can use "screen" util for that. Just connect to the server over SSH, start screen session by "screen" command execution, start your command there and disconnect (don't exit screen session). When you think your command already done you can connect to the server and attach to your screen session where you can see the command execution result/progress (in case one should be).

See "man screen" for more details.

This should resolve the problem for ubuntu and linux mint add:

ServerAliveInterval 120
TCPKeepAlive yes

to /etc/ssh/ssh_config file

Instead of screen I'd recommend tmux, an (arguably) better competitor to screen

tmux new-session -s {name}

That command creates a session. Any time after that you want to connect:

tmux a -t {name}

there are two solutions

  1. To update server and restart server sshd

echo "ClientAliveInterval 60" | sudo tee -a /etc/ssh/sshd_config

  1. To update client

echo "ServerAliveInterval 60" >> ~/.ssh/config

If you're still having problem after editing /etc/ssh/sshd_config or if ~/.ssh/config simply does not exist on your machine then I highly recommend reinstalling ssh. This solution took about a minute to fig both "Broken pipe" errors and "closed by remote host" errors.

sudo apt-get purge openssh-server

sudo apt update

sudo apt install openssh-server

jeremyforan's answer is correct, however I've found that if you are trying to use scp it is necessary to explicitly point it to a config file configured as described, it seems to not obey the normal hierarchy of config. For example:

scp -F ~/.ssh/config myfile joe@myserver.com:~

works, while omitting the -F still results in the broken pipe error.

After having tried to change many of above parameters in sshd_config (ClientAliveInterval, ClientMaxCount,TCPKeepAlive...) nothing had changed. I have spend hours and days to look for a solution on forums and blogs...

It appears that the problem of broken pipe which forbids to connect with ssh/sftp came from permissions settings on ChrootDirectory. the ChrootDirectory has to be owned by root/root with 755 permision lower permissions 765/766/775... won't work but strongers do (eg 700) if you need to give a write permission to connected user, you can give it in sub-directories. if chroot is owned by sftpUser:sftpGroup, it won't work neither...

chroot-> root:root 755
| 
---subdirectories-> sftpUser:sftpGroup 700 up to 770 

hope it would help

Ubuntu:
ssh -o ServerAliveInterval=5 -o ServerAliveCountMax=1 user@xxxx

I use an ASUS router with two internet input lines. I appoint my IP to a certain line, and it works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM