Horje
How to Add SSH Key to Your GitHub Account?

An SSH (Secure Shell) key is a pair of cryptographic keys used for authenticating and securing network communications over the SSH protocol. SSH keys are commonly used to securely access remote systems, transfer files, and execute commands on remote machines without passwords.

Components of an SSH Key

Private Key:

  • The private key is kept secret and stored securely on the user’s local machine.
  • It is used to decrypt encrypted messages with the corresponding public key.

Public Key:

  • The public key is meant to be shared with the remote systems you want to access.
  • It encrypts messages that can only be decrypted with the corresponding private key.

Now let’s start by generating an SSH key to be used in our Github account:

Step 1: Generate a New SSH Key

If you don’t already have an SSH key, you’ll need to generate one. If you already have one, you can skip to Step 2.

  • Open a terminal on your computer.
  • Generate a new SSH key using the ssh-keygen command:
ssh-keygen -t ed25519 -C "[email protected]"
  • If your system doesn’t support the ed25519 algorithm, you can use rsa:
ssh-keygen -t rsa -b 4096 -C "[email protected]"

Replace “[email protected]” with your GitHub email address.

Follow the prompts:

  • When asked to “Enter a file in which to save the key,” you can press Enter to accept the default location.
  • When prompted, you can optionally enter a passphrase for added security.
ss1

generating ssh-key

Note: It is asking for overwrite because i have already generated a ssh key earlier.

Step 2: Start the SSH Agent

  • Start the SSH agent in the background:
Start-Service ssh-agent
  • Add your SSH private key to the SSH agent:
ssh-add ~/.ssh/id_ed25519
  • If you used the RSA algorithm, the command will be:
ssh-add ~/.ssh/id_rsa
ss2

starting ssh service

Started the ssh-agent and added the private key.

Step 3: Add the SSH Key to Your GitHub Account

  • Copy the SSH public key to your clipboard:
cat ~/.ssh/id_ed25519.pub

If you used RSA:

cat ~/.ssh/id_rsa.pub
  • Select and copy the output starting with ssh-ed25519 or ssh-rsa.

Log in to your GitHub account.

Navigate to SSH and GPG keys settings:

  • Click on your profile picture in the top-right corner and select “Settings”.
  • In the left sidebar, click on “SSH and GPG keys”.
Screenshot-2024-05-24-164707

github option to add SSH keys

Add a new SSH key:

  1. Click on the “New SSH key” button.
  2. In the “Title” field, add a descriptive label for the new key (e.g., “My Laptop”).
  3. In the “Key” field, paste the SSH key you copied in Step 3.1.
  4. Click “Add SSH key”.
Screenshot-2024-05-24-164951

ssh key is added to github accou

Confirm your GitHub password to complete the process.

Screenshot-2024-05-24-165002

Successfully added ssh key:

Step 4: Test Your SSH Connection

  • Open a terminal.
  • Test the connection to GitHub
ssh -T [email protected]

You might see a warning the first time you connect:

The authenticity of host 'github.com (IP ADDRESS)' can't be established.
RSA key fingerprint is SHA256:...
Are you sure you want to continue connecting (yes/no)?

Type yes to continue.

  • Verify successful connection:

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

You’ve successfully added an SSH key to your GitHub account.

ss3

Successfully added ssh fingerprint

Now you can clone repositories, push changes, and perform other Git operations over SSH without needing to enter your password each time.




Reffered: https://www.geeksforgeeks.org


Git

Related
How To Delete Remote Branch in Git? How To Delete Remote Branch in Git?
How to Undo Git Reset? How to Undo Git Reset?
How to Ignore 'node_modules' Folder in Git? How to Ignore 'node_modules' Folder in Git?
Difference between .gitignore and .gitkeep Difference between .gitignore and .gitkeep
How to View Git Log of One User's Commits? How to View Git Log of One User's Commits?

Type:
Geek
Category:
Coding
Sub Category:
Tutorial
Uploaded by:
Admin
Views:
17