Adding a new ssh key to your github account

Here's a step-by-step guide on how to add a new SSH key to your GitHub account:

Prerequisites:

  1. You have a GitHub account.
  2. You have an SSH key pair (public and private keys) generated on your local machine.

Step 1: Create a new SSH key pair (if you don't have one already)

If you don't have an SSH key pair, you can generate one using the following command:

ssh-keygen -t rsa -b 4096

This will create a new SSH key pair in the default location (~/.ssh) with a filename like id_rsa and id_rsa.pub.

Step 2: Copy the public SSH key

Open the file id_rsa.pub (or the filename you specified during key generation) in a text editor. Copy the contents of the file.

Step 3: Add the SSH key to your GitHub account

  1. Log in to your GitHub account.
  2. Click on your profile picture in the top right corner, then click on "Settings".
  3. Click on "SSH and GPG keys" from the left-hand menu.
  4. Click on the "New SSH key" button.
  5. Paste the contents of your public SSH key into the "Key" field.
  6. Give your key a label (e.g., "My Laptop").
  7. Click on the "Add SSH key" button.

Step 4: Verify your SSH key

  1. Go back to your GitHub account's "SSH and GPG keys" page.
  2. You should see your new SSH key listed.
  3. Click on the "Verify" button next to your key.
  4. GitHub will attempt to connect to your machine using the new SSH key. If successful, you'll see a success message.

Step 5: Configure your Git client to use the new SSH key

  1. Open your Git client (e.g., Git Bash on Windows or Terminal on macOS/Linux).
  2. Run the following command to set the SSH key:
    git config --global user.sshKey /path/to/your/ssh/key

    Replace /path/to/your/ssh/key with the path to your private SSH key file (e.g., ~/.ssh/id_rsa).

Step 6: Test your SSH connection

  1. Run the following command to test your SSH connection:
    ssh -T [email protected]

    If everything is set up correctly, you should see a success message indicating that you're connected to GitHub using your new SSH key.

That's it! You've successfully added a new SSH key to your GitHub account.