打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
当SSH遇到“Write failed: Broken pipe” | 落格博客

在使用SSH管理服务器的时候,如果你很长一段时间不登录,那么很可能等待着你的就是

“Write failed: Broken pipe”

造成这个错误的原因是SSH空闲链接时间太长导致的,所以,我们需要修改SSH默认配置来让它自动关闭链接。

在SSH的配置当中,有两个命令可以实现这个功能,它们分别是

1
2
3
4
5
6
7
8
9
10
11
12
13
14
//ServerAliveInterval
         Sets a timeout interval in seconds after which if no data has
         been received from the server, ssh(1) will send a message through
         the encrypted channel to request a response from the server.  The
         default is 0, indicating that these messages will not be sent to
         the server.  This option applies to protocol version 2 only.
//ClientAliveInterval
         Sets a timeout interval in seconds after which if no data has
         been received from the client, sshd(8) will send a message
         through the encrypted channel to request a response from the
         client.  The default is 0, indicating that these messages will
         not be sent to the client.  This option applies to protocol
         version 2 only.

这两个命令前者应用在客户机上,后者应用在服务器上,如果你没有管理员权限,那么前者是很好的选择。
这两个的功能是相同的,都是开启一个发送keep-alive包的功能,这样会允许客户端/服务器在一定时间内发送一个特定的包给对方,一旦超时,则说明断线,就关闭链接。这样就避免了链接长时间挂着导致报错。而且,一旦再次报错,稍等片刻便可以再次登录啦。

总之,二者选择其一即可。

我们先来说服务器端的修改:

1
2
3
4
5
6
//编辑文件:
/etc/ssh/sshd_config
//在内容末尾添加如下语句:
ClientAliveInterval 60
//保存后重启服务:
/etc/init.d/ssh restart

这样,当服务器连续60秒没有接收到来自客户端的keep-alive包,就会关闭会话连接了。

接下来是客户端的修改办法:

如果你没有服务器权限,那么这是个不错的选择——而且,这种办法还有个进阶的使用方法——针对某个服务器单独设置idle时长:

1
2
3
4
5
6
7
//编辑文件:
~/.ssh/config
//在里边添加如下语句:
ServerAliveInterval 60
//针对某一服务器的写法:
//使用如下选项连接服务器:
ssh -o ServerAliveInterval=60 user@sshserver

anyShare分享到:

作者: R0uter

如非声明,本人所著文章均为原创手打,转载请注明本页面链接和我的名字。

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
ssh远程登录失败“Write failed:Broken pipe”
SSH端口转发实现内网穿透
SSH隧道与端口转发及内网穿透 | Creke Blog | 梦溪博客
Broken pipe错误终极解释
java.net.SocketException: Broken pipe
解决SSH Secure Shell Client中文乱码问题
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服