Setup an SSH key, and add SSH info to your config

Let’s say your ssh username is exampleUsername and your remote url is exampleSite.com
So typically when you ssh to that server, you do

$ ssh exampleUsername@exampleSite.com

Then you are prompted for your password, and then you are successfully logged into the server.

Let’s clean this up and make the process more efficient.

Create local SSH keys

This creates a local public and private key.  Both will be located in ~/.ssh
Public key- ~/.ssh/is_rsa.pub
Private key- ~/.ssh/is_rsa

$ ssh-keygen -t rsa

Fill out the prompts, or leave them blank.

Copy your SSH public key to the remote server

$ ssh-copy-id exampleUsername@exampleSite.com

 

Setup SSH config

Open ~/.ssh/config
If it does not exist, create it and add the following.

    Host exampleSiteName
        Hostname exampleSite.com
        Port 7822
        User exampleUsername
        ServerAliveInterval 240
        ServerAliveCountMax 2

Line 1-Replace “exampleSiteName” with the friendly name you want to connect to this site through ssh
Line 2- Replace “exampleSite.com” with the ssh url/ip
Line 3- Replace 7822 with the port.  if you do not have a port, remove this whole line
Line 4- Replace “exampleUsername” with your username.  This is the username you connect to ssh with and the same username as the key you copied to the server.
Line 5 + 6- These lines will keep your connection alive.  Remove these lines if you do not want that.

Test your new setup!

You should now be able to connect to your server like this

$ ssh exampleSiteName

This should connect to the remote server. You should not be prompted for a password if you copied your public key to the remote server.