背景
当使用ssh链接服务端后 如果一段时间不操作的话 terminal就会失去响应 有时还会报如下错误
- packet_write_wait: Connection to x.x.x.x port 22: Broken pipe
- Write failed: Broken pipe
解决办法
ssh链接时带上-o参数
ssh -o ServerAliveInterval=60 root@test
但是这样每次都要带上-o参数也很麻烦啊 可以使用如下办法解决
- alias别名
# 为了避免每次打开终端都执行改命令 把该命令放到~/.bashrc中 alias ssh='ssh -o ServerAliveInterval=60'
- 配置ssh参数
- 方式一
vi ~/.ssh/config ServerAliveInterval 60
- 方式二 参考
vi ~/.ssh/config #Added lines to fix. Host * IPQoS lowdelay throughput #end of new file edit
- 方式一
但是如果你经常要在不同的客户端上登录服务器也有点麻烦 可以使用如下办法
vi /etc/ssh/sshd_config
ClientAliveInterval 60