sshssh-tunnelssh-config

How to specify RemoteForward in the ssh config file?


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

Solution

  • 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