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:
- Log in to github.com.
- Click on your profile icon in the top right corner and select Settings.
- Under "Access", choose SSH and GPG keys.
- 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:
- Navigate to the repository you want to clone on GitHub.
- Click the green "Code" button and select the "SSH" option. Copy the URL.
- 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.