Git and SSH

Use SSH on GitHub

Below are the detailed step-by-step instructions for configuring and using SSH on GitHub from scratch:

Check for an existing SSH Key

First, check if you have an existing SSH key locally:

1
2
cd ~/.ssh
ls

If the id_rsa and id_rsa.pub files exist, an SSH Key already exists and you can skip the generation step.

Generate an SSH Key

If you do not have an SSH Key, you can generate one using the following command:

1
ssh-keygen -t rsa -C "your_email@example.com"

Press Enter to use the default settings.

Get SSH Public Key Content

After generating the SSH Key, get the content of the public key in one of the two ways:

  1. run the following command:
1
cat ~/.ssh/id_rsa.pub
  1. open id_rsa.pub file in txt

Copy the contents.

Add the Public Key on GitHub

→ Log in to GitHub → Go to Settings → Select SSH and GPG keys → Click New SSH key → Paste the copied contents of the public key into the Key text box → Click Add SSH key

Verify the SSH Configuration

Verify that the configuration was successful using the following command in the terminal:

1
ssh -T git@github.com

If it says Hi username! You've successfully authenticated, but GitHub does not provide shell access, then the configuration was successful.

Clone and Push Code

After successful configuration, you can clone and push code using SSH URLs.

  1. Clone the repository:
1
git clone git@github.com:username/repository.git
  1. Push the code:
1
2
3
4
cd repository name
git add
git commit -m "first-commit"
git push origin main
All Rights Reserved
Built with Hugo
Theme Stack designed by Jimmy