Adding a New SSH Key in GitHub

SSH key-based authentication provides a more secure alternative to password and access token. It also allows you to automate git operation using scripts or background processes.

Follow these steps to add a new ssh-key in your Github account.

  1. Check out the SSH Keys Available
  2. Create a new SSH key
  3. Add SSH Key to Github account
  4. Test Setup

1. Check out the SSH Keys Available

Log in to Unix/Linux to open a terminal. Check ~/.ssh/directory to search for ssh keys in your system. You can use key pair files from an existing system to configure Github.

In my case, I have the files.

ls-la /.ssh 


-rw ——- 2 root roots 568 Mar 7, 09:36 authorized_keys.-rw ——- 2 root roots 2602 Apr 1 02.53

2. Create a new SSH key

If there is no SSH key pair available, use the ssh-keygenCommand-line tool to generate new keys Type:


For any command-related input, hit enter


Generating public/private rsa key pair. Enter file in which to save the key (/home/rahul/.ssh/id_rsa):[Hit Enter]Enter your passphrase (empty if you don’t have one):[Hit Enter]Enter the same passphrase once more:[Hit Enter] Your identification has been saved in /home/rahul/.ssh/id_rsa Your public key has been saved in /home/rahul/.ssh/ The key fingerprint is: SHA256:WG+/Js/iM3kNfJ7Vf4iKHu/Jd2q3VffAnNAdyh/Rc7s [email protected]The key’s randomart picture is +—[RSA 3072]—-+ | o.| | …o=| | . .o..=| | o . +.o.| | . . =.=| | . .o .E*| | . ..* ++| | =*o*.B.o| | .ooB%=+…| +—-[SHA256]—–+

That’s all. Now you will see two key file created under the /.ssh folder. The private key (id_rsa), and the public key ( are the two key files.

Keep the private key file secured and don’t share with anyone.

3. Add SSH Key to Github account

You have now created an SSH pair on your system. Copy the contents of the public key (file with extension), and follow these steps to add ssh keys in Github account.

  1. Click on the profile icon in the upper-right corner and click Settings.Open Github User Settings
  2. In left sidebar, click GPG and SSH keys.SSH and GPG Keys in Github
  3. Click New SSH key
    Add new SSH Key in Github
    click “New SSH Key” button
  4. In the Key section, enter a title.
    Adding SSH Key in Github Account
    Adding SSH key
  5. Click Add SSH Key
  6. To authenticate, enter your password.
  7. All done

4. Test Setup

To verify settings, simply clone any repository that is accessible to your account using Git URL. Take this example:

git clone [email protected]:username/reponame.git 

This will authenticate your request using the SSH key pair. The repository will be cloned into your system after successful authentication.

Leave a Reply

Your email address will not be published. Required fields are marked *