What is SSH?

SSH is an industry standard used to connect to servers. It is more secure than the common password, and actually makes connecting much easier.

How does SSH Work?

When you generate an SSH key, you generate both a public key and a private key. The private key acts sort of like a password for your public key. For every server you want to connect to, you provide it your public key. You NEVER give ANYONE your private key.

How do we set up SSH?

For this tutorial I am going to assume you are on a mac. Open up terminal and run the following command:

ssh-keygen

Hit enter on the first question it asks you about where to store the file. We will use the default location.

Next, it will ask you for a password to protect your private key. Type in a secure password, and hit enter. Make sure you remember this password.

Great! You have now created your ssh key! What this command did is create a public key and private key. Your public key is named id_rsa.pub and your private key is named id_rsa

Now lets get our public key.

In terminal run:

cat ~/.ssh/id_rsa.pub

Copy the entire thing starting from and including ssh-rsa.

Now, connect to your linux server. Since we do not have ssh set up yet, you will either need to connect by using a password, or using the console in something like Digital Ocean.

Run ssh YOUR_USERNAME@YOUR_HOST or connect to it via console.

You will obviously need to replace YOUR_USERNAME with the proper username and YOUR_HOST with your server IP or a domain that resolves to that IP.

Once you are connected to your server, run:

nano ~/.ssh/authorized_keys

Keep any values that are in there already and paste your public key on the next available line.

Save the file and then disconnect from your server.

Testing our SSH Connection

Now that we have everything that we need set up, we can test our SSH connection. Close out any connections to your server.

Open up a terminal and run:

ssh YOUR_USERNAME@YOUR_HOST

For the first time connecting, a popup will appear asking for your password to the private key. Type it in and hit enter.

Awesome! You have now set up SSH to your server! Now follow the same steps for any computer/server combo you want to set up SSH server