SSH RemoteForward使用共享的控制套接字失败

我的〜/ .ssh / config包含:

ControlMaster auto ControlPath ~/.ssh/socket-%r@%h:%p Host hostname.example # TextMate rmate port RemoteForward :52698 localhost:52698 

当我与主机build立初始连接时,它在~/[email protected]:22成功创build主套接字文件。

但是,当我打开一个新的terminal,并尝试进行第二次连接,我得到这个错误:

 $ ssh hostname.example mux_client_forward: forwarding request failed: remote port forwarding failed for listen port 52698 muxclient: master forward request failed ControlSocket /Users/lachlanhunt/.ssh/[email protected]:22 already exists, disabling multiplexing Warning: remote port forwarding failed for listen port 52698 

但是,如果我在configuration文件中注释掉RemoteForward行,就能够成功地重新使用连接,使连接更快。 有什么办法可以configurationSSH来支持多路复用连接,并启用远程端口转发,使它只尝试转发端口,如果它是主连接?

我的系统:

  • macOS Sierra 10.12.6
  • OpenSSH_7.4p1,LibreSSL 2.5.0

我想出了一个解决scheme。 我使用与host匹配部分和否定exec关键字来testing主机名和控制套接字文件的存在。 如果文件不存在,那么这是主连接,所以设置端口转发。 否则,这是一个从属连接,转发被跳过。

 ControlMaster auto ControlPath ~/.ssh/socket-%r@%h:%p Match host hostname1.example.com,hostname2.example.com !exec "[ -e ~/.ssh/socket-%r@%h:%p ]" # TextMate rmate port RemoteForward :52698 localhost:52698