我从ssh_config手册页中看到,您可以共享host@user使用ControlPath和的连接ControlMaster。
有没有办法对本地用户、远程用户和远程主机的每个组合机会性地执行此操作?这样testuser@remotelaptop当您第二次通过 ssh连接时共享第一个连接并且第一个连接仍在运行?
(我使用 ssh 密钥。我不确定这是否会使它更容易或更难)。
从ssh_config手册页:
ControlMaster
...
Two additional options allow for opportunistic multiplexing: try
to use a master connection but fall back to creating a new one if
one does not already exist. These options are: “auto” and
“autoask”. The latter requires confirmation like the “ask”
option.
Run Code Online (Sandbox Code Playgroud)
因此,如果您使用 配置 ssh ControlMaster auto,它将尝试连接以使用现有的 SSH 会话,如果失败,则回退到创建新的主连接。
所以像下面这样的配置可能是你所追求的:
ControlMaster auto
ControlPath ~/.ssh/control/%r@%h:%p
Run Code Online (Sandbox Code Playgroud)