Adding a new ssh key to github account

To add a new SSH key to your GitHub account, follow these steps:

Step 1: Generate a new SSH key

  1. Open a terminal on your local machine.
  2. Run the command ssh-keygen -t rsa -b 4096 (or ssh-keygen -t ed25519 for a more secure option).
  3. Follow the prompts to save the key pair. You'll be asked to enter a file name and password. You can leave the file name as the default (id_rsa) and enter a password of your choice.
  4. Once the key pair is generated, you'll see two files: id_rsa (the private key) and id_rsa.pub (the public key).

Step 2: Copy the public key

  1. Open the id_rsa.pub file in a text editor.

  2. Copy the contents of the file. It should look something like this:

    ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8V9Ojtw7A+7WxT8bdB+GCBgih4=

    Step 3: Add the public key to your GitHub account

  3. Log in to your GitHub account.

  4. Click on your profile picture in the top right corner, then select "Settings".

  5. Click on "SSH and GPG keys" from the left-hand menu.

  6. Click the "New SSH key" button.

  7. Enter a title for the key (e.g., "My Laptop").

  8. Paste the public key you copied in Step 2 into the "Key" field.

  9. Click the "Add SSH key" button.

Step 4: Verify the key

  1. Go back to your terminal and run the command ssh -T [email protected] (replace github.com with your GitHub username).
  2. If everything is set up correctly, you should see a message indicating that you've successfully authenticated.

That's it! Your new SSH key should now be added to your GitHub account and you can use it to clone and push to your repositories.