Dwi Sulfahnur

How to setup Github push with SSH Keys

Every you push a commit to your repository, you usually have to enter your username and password. It will take much time and effort, In this post, i show you how to push your commit without enter username and password using ssh keys. So how to do it.

Generating a new ssh key.

Open your terminal Paste the text below, substituting in your GitHub email address.

ssh-keygen -t rsa -b 4096 -C "[email protected]"

This creates a new ssh key, using the provided email as a label. When you’re prompted to “Enter a file in which to save the key,” press Enter. This accepts the default file location. At the prompt, type a secure passphrase.

Adding your ssh key to the ssh-agents

Start the ssh-agent in the background.

eval "$(ssh-agent -s)"

Add your SSH private key to the ssh-agent. If you created your key with a different name, or if you are adding an existing key that has a different name, replace id_rsa in the command with the name of your private key file.

ssh-add ~/.ssh/id_rsa

Adding a new SSH key to your GitHub account

Copy the SSH Key to your clipboard. in this case, I using xclip tools to copy some text in terminal to my clipboard. so you have to install xclip by typing the following command in your terminal.(I use Ubuntu OS, adjust with your os)

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

In the upper-right corner of any page, click your profile photo, then click Settings.

Markdowm Image

In the user settings sidebar click SSH and GPG keys.

Markdowm Image

Click New SSH key or Add SSH key.

Markdowm Image

In the “Title” field, add a descriptive label for the new key. For example “My Ubuntu”.

Markdowm Image

Paste your key into the “Key” field. then, click Add SSH key.

Markdowm Image

If prompted, confirm your GitHub password.

Markdowm Image

Configure you Github Repository

In your terminal, go to your repository directory, then typing the following command. Adjust with your repository address.

git config remote.origin.url [email protected]:your_username/your_project.git

Backend Engineer