主机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或更大,保证不断开。

你可能感兴趣的:(linux)