SSH远程连接保持长时间不断开

解决办法:需要在Server端和Client端互相配置心跳参数,即发空包

- Server - ssh配置

[root@localhost ~]# vim /etc/ssh/sshd_config

....

 98 #PermitUserEnvironment no
 99 #Compression delayed
100 ClientAliveInterval 60       
101 ClientAliveCountMax 3
102 UseDNS no
103 #PidFile /var/run/sshd.pid
104 #MaxStartups 10:30:100
105 #PermitTunnel no
106 #ChrootDirectory none
107 #VersionAddendum none
....

ClientAliveInterval:指定了服务器端向客户端请求消息 的时间间隔, 默认是0, 不发送.
ClientAliveInterval 60:表示每分钟发送一次, 然后客户端响应, 这样就保持长连接了.
ClientAliveCountMax:表示服务器发出请求后客户端没有响应的次数达到一定值, 就自动断开,正常情况下, 客户端不会不响应,使用默认值3即可.

- 重启sshd服务

systemctl restart sshd 或 service sshd restart

- Client - ssh配置 【任选其一】

SSH Client 读取参数顺序 :命令行参数 ===> 用户配置文件 ===> 系统配置文件
● 1. SSH 命令行参数

ssh -o ServerAliveInterval=60 -o ServerAliveCountMax=3 root@192.168.1.1

● 2.用户配置文件 ~/.ssh/config

Host *
 ServerAliveInterval 60
 ServerAliveCountMax 3

● 3.系统配置/etc/ssh/sshd_config 追加以下内容

Host *
 ServerAliveInterval 60
 ServerAliveCountMax 3

- SSH Debug

☁  ~  ssh -vvv root@192.168.1.1 
OpenSSH_7.9p1 Deepin-deepin1 UOS_Desktop_104*, OpenSSL 1.1.1d  10 Sep 2019
debug1: Reading configuration data /home/mist/.ssh/config
debug1: /home/mist/.ssh/config line 13: Applying options for lt-zss
debug1: /home/mist/.ssh/config line 192: Applying options for *
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug2: resolve_canonicalize: hostname 192.168.1.1 is address
debug2: ssh_connect_direct
debug1: Connecting to 192.168.1.1 [192.168.1.1] port 22.
debug1: Connection established.
.....
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值