如何从 ssh 控制台取消本地端口转发

arc*_*rty 7 ssh

我可以使用以下命令转发本地端口

ssh> help
Commands:
      -L[bind_address:]port:host:hostport    Request local forward
      -R[bind_address:]port:host:hostport    Request remote forward
      -KR[bind_address:]port                 Cancel remote forward

ssh> -L 8080:localhost:8080
Forwarding port.
Run Code Online (Sandbox Code Playgroud)

但是如何取消那个端口转发呢?我看到取消远程转发的 -KR 但似乎没有取消我的本地转发的 -KL。

在同一个端口上请求另一个转发(希望覆盖旧的)会给出这个消息

ssh> -L 8080:localhost:8081
bind: Address already in use
channel_setup_fwd_listener: cannot listen to port: 10101
Run Code Online (Sandbox Code Playgroud)

小智 5

使用更新版本的 (open)ssh,还有一个转义命令可以取消本地转发:

ssh> help
Commands:
      -L[bind_address:]port:host:hostport    Request local forward
      -R[bind_address:]port:host:hostport    Request remote forward
      -D[bind_address:]port                  Request dynamic forward
      -KL[bind_address:]port                 Cancel local forward
      -KR[bind_address:]port                 Cancel remote forward
      -KD[bind_address:]port                 Cancel dynamic forward
Run Code Online (Sandbox Code Playgroud)