简体   繁体   English

如何在 ssh 配置文件中指定 RemoteForward?

[英]How to specify RemoteForward in the ssh config file?

I'm trying to setup a an ssh tunnel with remote port forwarding.我正在尝试设置一个带有远程端口转发的 ssh 隧道。 The idea is the have a VPS act as a means to ssh into remote deployed systems (which currently incorporate a Raspberry Pi).这个想法是有一个 VPS 作为 ssh 到远程部署系统(目前包含 Raspberry Pi)的一种手段。 Everything seems to work, but I run into issues when trying to move all arguments into the ~/.ssh/config file.一切似乎都正常,但是在尝试将所有 arguments 移动到 ~/.ssh/config 文件时遇到问题。 what does work is the setting of the HostName, User, Port and IdentityFile.起作用的是主机名、用户、端口和身份文件的设置。 However setting the RemoteForward parameter does not seem to work.但是,设置 RemoteForward 参数似乎不起作用。

The following works:以下作品:

ssh -R 5555:localhost:22 ssh-tunnel

How ever when using the following line in the config file;在配置文件中使用以下行时如何;

Host ssh-tunnel
    ...
    RemoteForward 5555 localhost:22

The following command returns the message "Bad remote forwarding specification 'ssh-tunnel'"以下命令返回消息“Bad remote forwarding specification 'ssh-tunnel'”

ssh -R ssh-tunnel

Obvious I found the answer almost immediately after posting the question.显然,我在发布问题后几乎立即找到了答案。 Using the -R flag requires you to set the remote forwarding in the command line call.使用 -R 标志需要您在命令行调用中设置远程转发。 However because remote forwarding is set in the config file you shouldn't add it to the command.但是,由于远程转发是在配置文件中设置的,因此您不应将其添加到命令中。 However something confusing occurs in that aside from setting up the tunnel you also ssh into the remote server.然而,除了设置隧道之外,您还可以将 ssh 连接到远程服务器中。 To avoid this add the -f and the -N flag.为避免这种情况,请添加 -f 和 -N 标志。 This results in the following command:这将导致以下命令:

ssh -f -N ssh-tunnel

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM