Make your life easy with SSH config speeding up your SSH login

Posted about 3 years ago

If you’re like me logging in and out of various SSH accounts on a day to day basis gets a bit laborious and it’s easy to forget the credentials, even with a password/notes program it can become tedious going in and finding all details.

Let’s assume our user is harambe and we’ve changed the standard SSH port for a little extra security to 2020. A conventional connection would look like so.

ssh -p 2020
password: *****

No, if you’re like me and hate passwords you will have gone ahead and set up public/private keys which doesn’t prompt you for a password. You can set up an alias so the below works.

ssh -p 2020

alias custom="ssh -p 2020"
custom #to connect

By typing custom it will connect (note: this can be called anything). Just add this into either your .bashrc or .zshrc


There’s a much more efficient way of solving this. If you don’t already have the file ~/.ssh/config go ahead and touch that and add the following

Host custom
    Port 2020
    User harambe
    IdentityFile /Users/<your-user>/.ssh/id_rsa_custom

By adding the IdentityFile I can explicitly tell the server where the private key is for authentication purposes so I don’t have to type in a password. I can go ahead now and type “custom” and I’ll be logged straight in.

ssh custom

NOTE: wherever we’ve used “custom” this can be whatever you like…  wookie, test, whatever… I like to abbriviate my server name, so for example I would call it cs1 and would type ssh cs1 (for client server one)