大网数据广告活动
服务器运维问答

Detecting stuck SSH control master sockets

· 52CE 我爱测

I use OpenSSH's ControlMaster features quite a bit to speed up new connections to a few systems which I use heavily. I have the following in my ~/.ssh/config : Host * ConnectTimeout 7 ControlMaster auto ControlPath ~/.ssh/control…

问题原文

原帖链接 · Dan Lenski · CC BY-SA 4.0

I use OpenSSH's ControlMaster features quite a bit to speed up new connections to a few systems which I use heavily.

I have the following in my ~/.ssh/config:

Host *
    ConnectTimeout 7
    ControlMaster auto                   
    ControlPath ~/.ssh/controlmasters/%r@%h:%p
    ControlPersist 10m    

Generally, this works great. However, there's one major annoyance: if the ControlMaster socket for a host gets “hung” due to a network interruption, ssh that_host just hangs forever. As far as I can tell, it literally never gives up on the existing ControlMaster socket and tries to create a new one. I have to manually ssh -O exit that_host before it will work.

What I really wish I could convince ssh to do is give up and tear down the ControlMaster socket if it can't connect within the ConnectTimeout.

Is there a missing ControlMasterConnectTimeout option which I'm missing? Or some other way I can convince ssh to detect and restart a dead ControlMaster socket?

已采纳解答

原帖链接 · nhed · CC BY-SA 4.0

TL;DR

Host *
    ServerAliveInterval 11

I'm guessing ConnectTimeout is not applicable here because the master is already connected.

This is not specific to ControlMaster but you could easily apply it just to relevant entries in your config.

You can use two different methods to detect stale connection:

  • TCPKeepAlive Uses mechanisms in the underlying socket.
  • ServerAliveInterval (upto ServerAliveCountMax consecutive failures)

I like the latter as there might be something else broken/hung that will be picked up and the manual also mentions possibility of spoofing.

Obviously you could choose another number. This variable in combination with ServerAliveCountMax (default 3) will determine when the connection will be dropped so I see things go away in about 33 seconds after i drop my vpn connection (I did not accurately measure this and noticed one session took a bit longer, but I applied this setting globally where maybe I should only apply it to the host I use with ProxyJump).

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2020-04-15)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。