How to specify RemoteForward in the ssh config file?
Asked Answered
B

1

17

I'm trying to setup a an ssh tunnel with remote port forwarding. The idea is the have a VPS act as a means to ssh into remote deployed systems (which currently incorporate a Raspberry Pi). Everything seems to work, but I run into issues when trying to move all arguments into the ~/.ssh/config file. what does work is the setting of the HostName, User, Port and IdentityFile. However setting the RemoteForward parameter does not seem to work.

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'"

ssh -R ssh-tunnel
Bareback answered 7/10, 2019 at 13:39 Comment(0)
B
5

Obviously 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. 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. To avoid this add the -f and the -N flag. This results in the following command:

ssh -f -N ssh-tunnel
Bareback answered 7/10, 2019 at 14:6 Comment(3)
Can you then please accept your own question? Many thanksJola
If you have already added RemoteForward 5555 localhost:22 to your config then you don't need to mention -R while doing ssh to the server. $ssh ssh-tunnel works perfectly.Farandole
As a side note, the -N is the same as SessionType none in the .ssh/config file. Similarly, the -f is the same as ForkAfterAuthentication yes. You may also need a few more options to make it all work as expected. Now, $ ssh ssh-tunnel really works as expected.Paltry

© 2022 - 2024 — McMap. All rights reserved.