SSH config for beginners

The SSH config is a powerful tool to get "more" out of your normal SSH connection.

Just create an file called "config" in your .ssh folder and it will be used on a new SSH session.

Lets start with a simple example of how a connection configuration could look like:

Host myHost
  Hostname 1.2.3.4 
  IdentityFile ~/.ssh/myHostKey
  User myUser

With this code, an "ssh myHost" will try to connect to the host 1.2.3.4 - using the user myUser and the keyfile myHostKey. And with this - you can use multiple keys and users on the same host without too much trouble 🙂

Another example with different ssh port:

Host myHost2
  Hostname myhost.com
  Port 3001
  User anotheruser
  IdentityFile ~/.ssh/anotherKey

You can also just give your ssh connection another keyfile:

Host github.com
  IdentityFile ~/.ssh/github

Forward a local port from your remote pc to yours:

Host myHost_tunnel
  Hostname myhost.com
  IdentityFile ~/.ssh/myHostKey
  User myUser
  LocalForward 443 127.0.0.1:443

Or even use your remote host as HTTP proxy (binding on your local port 8888):

Host myHost_proxy
  Hostname myhost.com
  IdentityFile ~/.ssh/myHostKey
  User myUser
  DynamicForward 127.0.0.1:8888

And the ssh config is even able to do a lot more but ... you'll find that in the manpage of ssh 🙂

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.