Why do I need .ssh/config?

When you use SSH to connect to a lot of different machines over the day, you’re dealing with different parameters and data such as various SSH Keys, ports, host names, and so forth. How do you remember all of this though? You might have this information in a text file somewhere or in a Wiki, yet still it is a lot of typing:

$ ssh deploy@test.server.com -p 3322 -i .ssh/deploy_key 

Can you remember all of these options? Don’t worry if you can’t. SSH comes with a solution for this.

.ssh/config

You might remember the .ssh directory from the SSH Primer, holding all our SSH Keys. When we add a config file, ssh will read it once we want to connect to a remote machine. .ssh/config allows us to configure a lot different things. Let’s explore how to configure host name, user, key and port:

Host staging
    HostName staging.example.com
    User deploy
    Port 7654
    IdentityFile ~/.ssh/deploy_rsa

Now, whenever we need to connect to the staging machine, we can type:

$ ssh staging

What other things do you configure in your .ssh/config? Share it in the comments!