Aditya Raj
Posted on May 10, 2024
Step by step instruction to setup GitHub SSH Keys and connect you github account to your local linux machine to push changes in your github repository
Step 1: Check for Existing SSH Keys
Before generating a new SSH key pair, it's essential to check if you already have existing keys. Open your terminal and run the following command:
ls -al ~/.ssh
- Look for files named id_rsa (private key) and id_rsa.pub (public key). If they exist, you can skip the key generation step.
Step 2: Generate SSH Key Pair
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
Replace "your_email@example.com" with the email address associated with your GitHub account.
Press Enter to accept the default file location and enter a passphrase if you want extra security.
Step 3: Start SSH Agent
eval "$(ssh-agent -s)"
Step 4: Add SSH Key to SSH Agent
- Add your SSH private key to the SSH agent by running:
ssh-add ~/.ssh/id_rsa
- If you set a passphrase during key generation, you'll need to enter it here.
Step 5: Add SSH Key to GitHub
Now, you need to add your SSH public key to your GitHub account. Display the contents of your public key by running:
cat ~/.ssh/id_rsa.pub
Copy the output and follow these steps :
- Go to your GitHub account settings.
- Navigate to "SSH and GPG keys".
- Click on "New SSH key" or "Add SSH key".
- Paste your SSH public key into the provided field and give it a title.
- Click "Add SSH key".
Step 6: Test SSH Connection
To test if your SSH key is set up correctly, run the following command:
ssh -T git@github.com
If everything is set up correctly, you'll see a message confirming your connection.
That's it! You've successfully set up SSH keys for your GitHub account on your Linux machine. Now you can clone, push, and pull repositories using SSH without the hassle of entering your credentials every time.
PS: When you will commit your changes for the first time, you will be asked to enter github configuration details like your name and email address.
Posted on May 10, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.