Skip to main content

Create SSH Key

This guide will help you generate a SSH key pair and use it with your GitHub account.

Step 1: Creating the SSH Key

  1. Open your terminal (Windows: Git Bash, macOS/Linux: Terminal).

  2. Run the following command to generate a new SSH key pair:

    ssh-keygen -t ed25519
  3. When prompted for a file to save the key, press Enter to accept the default location (~/.ssh/id_ed25519).

  4. Press Enter twice to leave the passphrase empty.

  5. Your SSH key pair will be created, and placed in the ~/.ssh directory. The public key ends with .pub.

Step 2: Add the SSH Key to your GitHub Account

  1. Copy the contets of your public key to the clipboard:

    cat ~/.ssh/id_ed25519.pub | pbcopy # macOS
    cat ~/.ssh/id_ed25519.pub | clip # Windows (Git Bash)
  2. Navigate to this link GitHub settings.

  3. Click on New SSH key.

  4. Paste your public key into the "Key" field.

  5. You can skip the "Title" field or give it a descriptive name.

  6. Click Add SSH key to save it.

Step 3: Test the SSH Connection

  1. In your terminal, run the following command to test the connection:

    ssh -T git@github.com
  2. If everything is set up correctly, you should see a message like:

    Hi username! You've successfully authenticated, but GitHub does not provide shell access.
  3. If you see a warning about the authenticity of the host, type yes to continue.

Step 4: Cloning a Repository using SSH

Now that you have your SSH key set up, you can clone repositories using SSH:

git clone git@github.com:username/repo.git
  • replace the username with your GitHub username and repo.git with the repository you want to clone.