SSH config file

SSH config file

I learned a neat trick lately that has to do with SSH. If you are like me and use secure shell to connect to a remote box or for git push/pulls then you most likely be interested in this next little configuration file.

As you probably know, all your ssh configurations and keys probably reside in the .ssh folder of your home directory.
Go to this directory and use vim to create a file named config.

vim ~/.ssh/config

Lets add a host definition.
(I do recommend a non privileged user for ssh’ing, you can always su or sudo later)

Host mybox
    Hostname 192.168.2.100
    Port 22
    User root

Now if you do.

ssh mybox

SSH will look for “mybox” in the config file and execute the following equivalent.

ssh root@192.168.2.100

Cool no? Now you might ask why all this for just a little bit of less typing, well it gets pretty neat if you work with public/private keys.

Create a file with your github private key and name it github.key, save it into your ~/.ssh/ folder.

Now add:

Host github.com
    IdentityFile ~/.ssh/github.key.

This will make git (over ssh) actions for the github.com domain use this specific key.

Leave a Reply

Your email address will not be published. Required fields are marked *

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