Skip to content

Creating and Using an SSH Key with GitHub

Generating a New SSH Key

  1. Open a terminal and run the following command to generate a new SSH key with the highest encryption (Ed25519):

    sh
    ssh-keygen -t ed25519 -C "kelly.carinola@gmail.com"
  2. When prompted, specify a file to save the key (press Enter to accept the default location):

    sh
    Enter file in which to save the key (/home/your_user/.ssh/id_ed25519):
  3. Enter a passphrase for added security (optional but recommended):

    sh
    Enter passphrase (empty for no passphrase):
    Enter same passphrase again:

Adding Your SSH Key to the SSH Agent

  1. Start the SSH agent in the background:

    sh
    eval "$(ssh-agent -s)"
  2. Add your SSH private key to the SSH agent:

    sh
    ssh-add ~/.ssh/id_ed25519

Adding Your SSH Key to Your GitHub Account

  1. Copy the SSH key to your clipboard:

    sh
    cat ~/.ssh/id_ed25519.pub
  2. Log in to your GitHub account and go to the SSH and GPG keys settings:

    • Navigate to Settings > SSH and GPG keys > New SSH key
  3. Paste your SSH key into the "Key" field and give it a descriptive title:

    • Click Add SSH key

Testing Your SSH Connection

  1. Run the following command to test your SSH connection:

    sh
    ssh -T git@github.com
  2. You should see a message like this:

    sh
    Hi username! You've successfully authenticated, but GitHub does not provide shell access.

Generating a New GPG Key

  1. Open a terminal and run the following command to generate a new GPG key:

    sh
    gpg --full-generate-key
  2. Follow the prompts to specify the key type, size, and expiration date. Use your GitHub email address:

    sh
    Real name: <name>
    Email address: <your@email.com>
  3. Enter a passphrase for added security (optional but recommended):

    sh
    Enter passphrase:

Adding Your GPG Key to Your GitHub Account rtql8ive

  1. List your GPG keys and copy the GPG key ID:

    sh
    gpg --list-secret-keys --keyid-format LONG
  2. Export your GPG key to your clipboard:

    sh
    gpg --armor --export YOUR_KEY_ID  # Replace YOUR_KEY_ID with the GPG key ID
    
    gpg --armor --export BB0C7B1A33F83322
  3. Log in to your GitHub account and go to the SSH and GPG keys settings:

    • Navigate to Settings > SSH and GPG keys > New GPG key
  4. Paste your GPG key into the "Key" field and give it a descriptive title:

    • Click Add GPG key

By following these steps, you can create both SSH and GPG keys with the highest encryption and use them to securely connect to your GitHub account.