Ssh – How to forward a range of ports in ssh config

port-forwardingsshssh-configssh-tunneling

I understand that I can forward multiple port in ssh config file by:

Host name
    HostName yam.myHost.edu
    User myUserName
    LocalForward 5901 127.0.0.1:5901
    LocalForward 5902 127.0.0.1:5902
    [...]
    LocalForward 5910 127.0.0.1:5910

Is there any easier way to forward a range of ports without the need to add extra line for a port?
Something like LocalForward 5901-5910 127.0.0.1:5901-5910 ?

Best Answer

I'm doing this usually without config, interactively in the command line like this

ssh yam.myHost.edu $(for i in `seq 5901 5920` ;do echo -L $i:localhost:$i ;done)

You could also generate the config file lines and copy/paste it to your config file:

for i in `seq 5901 5920` ;do echo "LocalForward $i localhost:$i" ;done
LocalForward 5901 localhost:5901
LocalForward 5902 localhost:5902
LocalForward 5903 localhost:5903
[...]
Related Question