主机ssh长连接远程服务器

本文介绍如何通过修改Ubuntu服务器的sshd_config文件,设置ClientAliveInterval和ClientAliveCountMax参数,来保持SSH连接的持久性和稳定性,避免因服务器端请求未得到及时响应而频繁断开连接。

我购买一台远程服务器(Ubuntu 19.04),每次本地主机访问ssh远程服务器时,连接时间特别短!!!

解决方法

root@vultr:~# vim /etc/ssh/sshd_config   //服务器端编辑sshd_config文件
#sshd_config
# PAM authentication via ChallengeResponseAuthentication may bypass
# the setting of "PermitRootLogin without-password".
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and ChallengeResponseAuthentication to 'no'.
UsePAM yes

#AllowAgentForwarding yes
#AllowTcpForwarding yes
#GatewayPorts no
X11Forwarding yes
#X11DisplayOffset 10
#X11UseLocalhost yes
#PermitTTY yes
PrintMotd no
#PrintLastLog yes
#TCPKeepAlive yes
#PermitUserEnvironment no
#Compression delayed
ClientAliveInterval 30      //指定server向host请求消息的时间间隔,默认是0,不发送。当clientAliveInterval=60表示每半分钟发送一次,然后客户端响应。
ClientAliveCountMax 999999999  //默认数值是3,clientAliveCountMax表示服务器发出请求后客户端没有响应的次数达到一定值,就自动断开。我亲自实测,数值`越大`,连接时长越长。正常情况下,client不会不响应的。

总结 
ClientAliveInterval 60表示每分钟发送一次,然后客户端响应,这样就保持长连接了。ClientAliveCountMax,使用默认值3即可,ClientAliveCountMax表示服务器发出请求后客户端没有响应的次数达到一定值,就自动断开,设成10000或更大,保证不断开。

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值