SSH Port forwarding in a ~/.ssh/config file?

Snow_Mac picture Snow_Mac · Feb 5, 2012 · Viewed 108.5k times · Source

So I typically run this command a lot:

ssh -L 5901:[email protected]:5901

I use it to do VNC over SSH.

How do I convert that command into something that will work in a ~/.ssh/config file?

ex:

host yam
    HostName yam.myHost.edu
    User myUserName

all I want to do is type:

ssh yam

And have it open a SSH shell with a local listen port, and a remote port forwarded to it.

Suggestions?

Answer

Johnsyweb picture Johnsyweb · Feb 5, 2012

You can use the LocalForward directive in your host yam section of ~/.ssh/config:

LocalForward 5901 computer.myHost.edu:5901