Push code via SSH keys

I was facing problem i.e I was unable to push code on GitHub from home network. Whenever I tried to push or clone code, it  was giving below error:

error: RPC failed; result=7, HTTP code = 0
fatal: The remote end hung up unexpectedly

This problem was coming with https protocol. Then I tried to solve problem with another method. I used SSH to fix above error.

How I solved  above error?

I used SSH keys instead of https. In this method, you will generate your public key and attach that key with  your GitHub account.

Step1: Install OpenSSH:

sudo apt install openssh-server

Step 2: clone repository with ssh:


But it will give below error because you did not generate and connect public key.


Step 3: Generating public/private rsa key pair:

$ ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

Step 4: List the files and directories in your ssh folder:

$ ls -al ~/.ssh

Step 5: Check that you are connecting to the correct server:

To make sure you are connecting to the right domain, you can enter the following command:


Note the IP address (the numbers within the [] brackets). The connection should be made to a GitHub IP address, on port 22.

Step 6: Add your SSH  key to the ssh-agent:

$ ssh-add

Step 7: Verify that you have a private key generated and loaded into SSH. If you’re using OpenSSH 6.7 or older:

$ eval "$(ssh-agent -s)"
$ ssh-add -l

Step 8: Add your SSH key to your account:

$ sudo apt-get install xclip 
$ xclip -sel clip < ~/.ssh/id_rsa.pub

Then add the copied key to GitHub. Go to Settings->SSH keys(Personal settings side bar)->Add SSH key->fill out form(key is on your clipboard, just use ctrl+v)->Add key.

Done 🙂

Now you can clone and push code via SSH keys :-). See


Enjoy 🙂



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s