✨ Best Method ✨

1. Make keys

Make private + public keys. You can do this with ssh-keygen on Linux/Mac and PuttyGen on Windows.

2. Put Public Key in Destination

2.1 GitLab / GitHub / etc

For a website this means saving the appropriately formatted public key into the text box they provide.

2.2 A Server

For connecting to another machine you use ssh-copy-id. It will copy the key into ~/.ssh/authorized_keys on the server. It looks like this:

$ ssh-copy-id -i ~/.ssh/id_rsa.pub user@host
# Checks if key already works
user@host's password: # Password if needed
# Success!

The -i stands for "identity file".

3. Add Private Key to Config File

There's a bunch of crap about adding your key to your ssh agent which is all trash because you can get around it by making a config file. Specifically ~/.ssh/config. It should look like this:

# Example for GitLab
Host gitlab.com
  PreferredAuthentications publickey
  IdentityFile ~/.ssh/gitlab_com_rsa

4. Test the Connection

And that's it!

📑Command Reference

Mostly for Windows cos ssh on Windows is trash.