SSH的 Write failed: Broken pipe 问题
问题现象:
表示连接管道已经断开
解决方法:
方法一:客户端配置
在客户端的 ~/.ssh/ config文件(如不存在请自行创建)中添加下面内容:
ServerAliveInterval 60
方法二:服务器端配置
在服务器的 /etc/ssh/sshd_config 中添加如下的配置:
ClientAliveInterval 60
方法三:临时SSH命令配置
如果只是临时性的连接(即只作用于当前SSH),可以直接使用 ssh 命令参数进行配置。
$ ssh -o ServerAliveInterval=60 user@sshserver
1 2 3 4 5 6 7 8 9 10 11 12 13 | //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包的功能,这样会允许客户端/服务器在一定时间内发送一个特定的包给对方,一旦超时,则说明断线,就关闭链接。这样就避免了链接长时间挂着导致报错。而且,一旦再次报错,稍等片刻便可以再次登录。
每天记录一点,就能多学一点,充实一点
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· 周边上新:园子的第一款马克杯温暖上架
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?
· 使用C#创建一个MCP客户端