How to clone a GitHub repository with an SSH key

Last update: 06-21-2024

Welcome! In this guide we will walk through the process of setting up an SSH key on a Linux machine and use it to clone a GitHub repository.

Update Your System

sudo apt update

Install Git

sudo apt install git

Verify the installation by checking the Git version:

git --version

Prepare your GitHub account to work with SSH Keys

Follow these steps to create and add your SSH key to GitHub:

    1. Log in to github.com.
    2. Click on your profile icon in the top right corner and select Settings.
    3. Under "Access", choose SSH and GPG keys.
    4. Click on New SSH key.

Generate the SSH Key in Your Linux Machine

Open your terminal and generate a new SSH key:

ssh-keygen -t ed25519 -C "your_email@example.com"

Press 'Enter' for each prompt to accept the default settings.

Display and copy your new public SSH key:

cat /home/username/.ssh/id_ed25519.pub

Back in GitHub, provide a name for your key under 'title' and paste the key under 'key'. Then click Add SSH key.

Cloning a Repository

To clone a repository from GitHub:

    1. Navigate to the repository you want to clone on GitHub.
    2. Click the green "Code" button and select the "SSH" option. Copy the URL.
    3. In your terminal, run:
git clone git@github.com:Username/repoName.git

Replace 'Username' and 'repoName' with your actual GitHub username and repository name.

You might be prompted to verify the server's authenticity. Type "yes" and press Enter.

Your repository will now be cloned to your machine.

0 Comments

Add a new comment: