当前位置: 首页 > article >正文

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.
.....

http://www.kler.cn/news/327606.html

相关文章:

  • 鸿蒙NEXT开发-自定义构建函数(基于最新api12稳定版)
  • react+antdMobie实现消息通知页面样式
  • 大模型部署——NVIDIA NIM 和 LangChain 如何彻底改变 AI 集成和性能
  • 原生 React Native 和 Expo对比
  • 玄武星辰大阵——软件终端架构思维———未来之窗行业应用跨平台架构
  • Linux shell编程学习笔记84:tee命令——显示保存两不误
  • 微信小程序:一个小程序跳转至另一个小程序
  • 理解C语言之深入理解指针(四)
  • 基于Springboot+Vue的基于协同过滤算法的个性化音乐推荐系统 (含源码数据库)
  • WMware安装WMware Tools(Linux~Ubuntu)
  • 共筑数据安全防线!YashanDB与SPU完成兼容性互认证
  • 《蓝桥杯算法入门》(C/C++、Java、Python三个版本)24年10月出版
  • Python的异步编程
  • 【分布式微服务云原生】gRPC与Dubbo:分布式服务通信框架的双雄对决
  • DAY81服务攻防-开发框架安全SpringBootStruts2LaravelThinkPHPCVE 复现
  • SOMEIP_ETS_142: SD_Request_non_existing_Major_Version
  • 速盾:游戏用CDN可以吗?
  • 桥接(桥梁)模式
  • Android DataBinding的使用
  • pytorch之自动求导
  • 官网:视觉是第一记忆,没有记忆点的官网设计是失败的。
  • 【Ubuntu】安装常用软件包-mysql
  • Meta Llama 3.2发布:小型文本模型与多模态视觉能力,AI的未来已来!
  • CC面试准备
  • 如何从huggingface下载
  • C++杂项
  • 裸金属服务器与虚拟机、物理机区别
  • 基于SpringBoot+Vue+MySQL的美食信息推荐系统
  • 大联大友尚集团推出基于炬芯科技产品的蓝牙音箱方案
  • INTO:Web3世界的“价值引力场”