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

How to temporarily disable local forwards

· 52CE 我爱测

I have in my ~/.ssh/config file entries with local forward definitions like HOST myServer hostname 10.10.0.1 user xyz LocalForward 8080 localhost:80 LocalForward 4000 127.0.0.1:4000 ... This works like a charm, but I also have sc…

问题原文

原帖链接 · jeb · CC BY-SA 3.0

I have in my ~/.ssh/config file entries with local forward definitions like

HOST myServer
   hostname 10.10.0.1
   user xyz
   LocalForward 8080 localhost:80
   LocalForward 4000 127.0.0.1:4000
   ...

This works like a charm, but I also have scripts to synchronize some data.
These scripts show many warnings when they try to connect to the server while there is already a connection.

bind: Address already in use
channel_setup_fwd_listener_tcpip: cannot listen to port: 8080
bind: Address already in use
channel_setup_fwd_listener_tcpip: cannot listen to port: 4000
....

Is there a neat way to use ssh or rsync with an option to disable all local forwards for a session?

Obviously I could copy&paste each config block and build one with and one without local forwards, but I hope there is a better solution.

已采纳解答

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

There is ClearAllForwardings option in ssh_config, which does exactly what you need:

ClearAllForwardings

Specifies that all local, remote, and dynamic port forwardings specified in the configuration files or on the command line be cleared. This option is primarily useful when used from the ssh(1) command line to clear port forwardings set in configuration files, and is automatically set by scp(1) and sftp(1). The argument must be yes or no (the default).

You can use it as a commandline option:

ssh -o ClearAllForwardings=yes host

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

资料来源与适用范围

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

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

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