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:
- You have a GitHub account.
- 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
- Log in to your GitHub account.
- Click on your profile picture in the top right corner, then click on "Settings".
- Click on "SSH and GPG keys" from the left-hand menu.
- Click on the "New SSH key" button.
- Paste the contents of your public SSH key into the "Key" field.
- Give your key a label (e.g., "My Laptop").
- Click on the "Add SSH key" button.
Step 4: Verify your SSH key
- Go back to your GitHub account's "SSH and GPG keys" page.
- You should see your new SSH key listed.
- Click on the "Verify" button next to your key.
- 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
- Open your Git client (e.g., Git Bash on Windows or Terminal on macOS/Linux).
- 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
- 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.