Skip to main content

SSH Keys

SSH keys are a form of access credential used in the SSH protocol. They come in pairs - a private key and a public key. To authenticate a key, you generally save the public key (never the private one) on the service which you are connecting to via SSH. When you are on the machine which has the private key associated with that public key, it will be authenticated.

Creating an SSH key

  1. Open your terminal. On macOS, you can find this in Utilities in the Applications folder.
  2. Run the following command in the terminal:
ssh-keygen -t rsa
  1. It then asks you a couple of questions:
    1. It prompts you about where to store the key, the default location is fine
    2. It prompts you for a passphrase. You can add one or leave this blank
  2. After you confirm, it generates the key pairs and stores them in /Users/<USERNAME>/.ssh/ as id_rsa as the private key and id_rsa.pub as the public key

Authenticating with the SSH key

To get the public key, you can run the following command in your terminal:
cat /Users/<USERNAME>/.ssh/id_rsa.pub
You will then see a key starting with ssh-rsa in your terminal. You can copy and paste that key onto the service you want to authenticate with.