Saving SSH options for specific host


Who doesn’t know that problem. You are working on a bunch of different hosts via ssh, and on all of them you need specific SSH Options. On the first the port differs, on the second you need to login with a different user than you are connected right now, on the third you need X-Forwarding and on the fourth you want to redirect a remote port to a local one. I knew that it is possible to save host-specific options in a ssh config file, but I never got arround to take a look at it. Now I found exactly that question – and the answer – in the popular german computer magazine CT. The file is

~/.ssh/config

The structure is rather simple. You specify a connectionname via

Host CONNECTIONNAME

and the belonging host via

HostName HOSTNAME

After that you can specify any options you want to for the connection (see man ssh_config). You can do it for as many hosts as you want. I just set it up and it is just to cool how much time it saves not to type all the stuff all the time.

Example:

Host stiffmaster
HostName 192.168.6.112
User prego
Port 33
LocalForward 6312 localhost:631
ForwardX11 yes

Now you just type ssh stiffmaster instead of ssh -X -L 6312:localhost:631 -p 33 prego@192.168.6.112. Isn’t that cool?? :-)

,

5 Antworten zu “Saving SSH options for specific host”

  1. DUDE, do you know how long I’ve just created bash aliases?
    stuff like:
    alias bricker=’ssh -L 5901:localhost:5901 user@bricker.fqdn.tld‚ ?
    I even have an alias that has no less than 3 (maybe 4?) port forwards.

    All I can say it, THANK YOU for this post. And THANK YOU for Larry the Cow, This is such a very awesome tip!

  2. […] SSH gehoert fuer mich zum taeglich Brot. Gefuehlte 1.000.000 mal taeglich baue ich Verbindungen zu irgendwelchen Servern auf, mache dort etwas, baue die Verbindung wieder ab usw… Etwas was mir mein Leben dabei sehr stark erleichtert ist die ~/.ssh/config in der ich fuer die entsprechenden Server die Voreinstellungen hinterlegt habe. Vor vielen Jahren hatte ich darueber bereits hier auf dem Blog geschrieben. […]

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht.

Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden.