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
- Open a terminal on your local machine.
- Run the command
ssh-keygen -t rsa -b 4096
(orssh-keygen -t ed25519
for a more secure option). - 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. - Once the key pair is generated, you'll see two files:
id_rsa
(the private key) andid_rsa.pub
(the public key).
Step 2: Copy the public key
-
Open the
id_rsa.pub
file in a text editor. -
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
-
Log in to your GitHub account.
-
Click on your profile picture in the top right corner, then select "Settings".
-
Click on "SSH and GPG keys" from the left-hand menu.
-
Click the "New SSH key" button.
-
Enter a title for the key (e.g., "My Laptop").
-
Paste the public key you copied in Step 2 into the "Key" field.
-
Click the "Add SSH key" button.
Step 4: Verify the key
- Go back to your terminal and run the command
ssh -T [email protected]
(replacegithub.com
with your GitHub username). - 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.