DEV Community

Collins Ruto
Collins Ruto

Posted on β€’ Edited on β€’ Originally published at collinsruto.vercel.app

GitHub SSH for Linux & ALX SandBox

Introduction

GitHub SSH (Secure Shell) is a secure protocol used to establish a secure encrypted connection between a local machine and GitHub's remote servers. It allows you to securely authenticate and communicate with GitHub without relying github token and also since passwords deprecated and unsuported.

When using SSH with GitHub, you generate a key pair consisting of a public key and a private key. The public key is stored on GitHub, while the private key remains on your local machine. The private key should be kept confidential and protected with a passphrase.

Sandbox/Terminal setup

To begin, go to your ALX Sandbox and run your sandbox through your preferred method.

Generate SSH key

To generate your ssh key, run the following command on your sandbox/terminal.

ssh-keygen -t ed25519 -C "your_email@example.com"
Enter fullscreen mode Exit fullscreen mode

You will be prompted to Enter a file in which to save the key, press enter to save in the default location. You will then be prompted to enter a passphrase, just press enter or input one and repeat the same if you prefer it.

Get your SSH key

The generated SSH key is now stored in the ~/.ssh/id_ed25519 directory. To access the new SSH public key, run the command below then select and copy the output.

cat ~/.ssh/id_ed25519.pub
Enter fullscreen mode Exit fullscreen mode

Copy this value as it is required for later steps in setting up GitHub.
The output should something similar to:

ssh-ed25519 Some-long-string-of-characters-here your-email@gmail.com
Enter fullscreen mode Exit fullscreen mode

GitHub Setup

Now we need to add our generated SSH public key to GitHub account.
Click here and you will be directed to your GitHub new SSH Keys page.

Alternatively, go to your GitHub account settings and navigate to the "SSH and GPG keys" section and click on "New SSH key".
You should see a similar page.

Add SSH GitHub

On mobile phones, scroll down to the section.

On the Title input field, give your ssh key a name e.g "ALX-Sandbox".

Thereafter on the key input field, paste the public key that we copied from the sandbox output.

Click Add SSH key.

You will be prompted to enter you GitHub account password to authorize adding the Key.

Update your git identity

If you haven't updated your git identity on your sandbox/terminal before, do the following commands and be sure to substitute with your actual username and email:

git config --global user.email "you@example.com"
git config --global user.name "Your Name"
Enter fullscreen mode Exit fullscreen mode

This helps to create a local git profile for local git commits and activities.

3 Test

Now that we have successfully added our public key to github, we have to test our connection.

Open up your sandbox and run the following:

ssh -T git@github.com
Enter fullscreen mode Exit fullscreen mode

This attempts to connect to GitHub via ssh. If everything is set correctly, it would return something like this:

The authenticity of host 'github.com (IP ADDRESS)' can't be established.
ED25519 key fingerprint is SHA256:+....> Are you sure you want to continue connecting (yes/no)?
Enter fullscreen mode Exit fullscreen mode

Type yes on the terminal to confirm.

You are now connected!

Using SSH

Lets try using the new ssh in a real project.

Firstly create a new repository here: new empty repository and give a name and optional description.

Do NOT select add README file, .gitignore or license.

New github repository

click on 'create repository'.

Cloning the repository

You will be navigated to the created repository page. Click on the ssh tab as shown below arrow 1:

Git SSH

Copy the preceding git ssh url, substituting for your username and the name of your repository. Which in the case of the screenshot above is like so on arrow 2:

git@github.com:your-username-here/repo-name-here.git
Enter fullscreen mode Exit fullscreen mode

On your terminal/sandbox, clone the repo by running the following, substituting for your username and the name of your repository:

git clone git@github.com:your-username-here/repo-name-here.git
Enter fullscreen mode Exit fullscreen mode

This should create an empty directory with name repo_name_here inside it. You may now make changes to your project as you wish and push them to GitHub directly. Go to your repository and refresh the page to confirm changes.

If you are asked to authorize your SSH key after running git push as such:

The authenticity of host 'github.com (IP ADDRESS)' can't be established.
ED25519 key fingerprint is SHA256:+....> Are you sure you want to continue connecting (yes/no)?
Enter fullscreen mode Exit fullscreen mode

Type yes on the terminal to confirm.

You are now connected and your changes will be pushed.

Do your career a big favor. Join DEV. (The website you're on right now)

It takes one minute, it's free, and is worth it for your career.

Get started

Community matters

Top comments (2)

Collapse
 
sue2023 profile image
SUE2023 β€’

Thanks for the article, simple and easy to follow. Has helped me submit study projects.

Collapse
 
collinsruto profile image
Collins Ruto β€’

Awesome πŸ‘.
Happy I could help 😁

Image of Docusign

πŸ› οΈ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

πŸ‘‹ Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay