How to Set Up SSH Keys for GitHub on PopOs or Ubuntu: A Beginner’s Guide

Introduction

In this guide, you’ll learn how to generate an SSH key and set it up with GitHub. SSH keys provide a secure way to access GitHub without needing to repeatedly enter your password, making your workflow faster and more secure.


This content originally appeared on DEV Community and was authored by Alexandre Calaça

Introduction

In this guide, you’ll learn how to generate an SSH key and set it up with GitHub. SSH keys provide a secure way to access GitHub without needing to repeatedly enter your password, making your workflow faster and more secure.

Solution

Generate a new SSH key

To generate a new SSH key, run the following command in your terminal:

ssh-keygen -t ed25519 -C "any comment"

This command uses the ed25519 algorithm, which is considered both secure and efficient. Replace "any comment" with something descriptive, like your email or a short label.

This comment will help you identify your key later, especially if you manage multiple SSH keys.

Output

Image Pattern

Enter file

You’ll be prompted to choose where to save the key file. By default, the SSH key is saved in the ~/.ssh directory with a generic name like id_ed25519.

If you’d like to name the key something else (e.g., pop_os_athanasius), you can enter the file path here.

If you want to keep it as the default, simply press Enter.

In this example, we’ll name it /home/athanasius/.ssh/pop_os_athanasius.

Output

Image Enter file

Enter passphrase

You’ll be prompted to enter a passphrase to protect your key. Using a passphrase is recommended for added security.

However, if you prefer to leave it blank, just press Enter twice. Keep in mind that without a passphrase, anyone with access to your machine can use this key.

In this example, we’ll leave it blank for simplicity.
Output

Image Enter passphrase

Verify the key generation

Once the key generation process is complete, you should see a confirmation message showing the key’s fingerprint. This unique identifier verifies the key was created successfully.

View the public key

To connect your SSH key with GitHub, you’ll need to add the public key to your GitHub account. To display your public key in the terminal, run:

cat ./.ssh/pop_os_athanasius.pub

Adding the SSH Key to GitHub

With your SSH key ready, it’s time to add it to GitHub for secure access.

Access GitHub Settings

Navigate to GitHub, log in, and go to Settings. You can find this option in the drop-down menu under your profile icon.

Image Settings

Open the SSH and GPG Keys Section

In the Settings menu, find and click on SSH and GPG keys from the sidebar. This section is where you’ll add new SSH keys to your GitHub account.

Image SSH and GPG keys

Add a New SSH Key

Click New SSH key. You’ll be prompted to enter a title and paste your key.

Image New SSH Key

Save the key

Click Add SSH key to save it to your GitHub account. You may be prompted to confirm this action with your GitHub password.

Image Add the SSH key

Check connection

With your key added, let’s test the connection to GitHub. This step verifies that everything is configured correctly.

Run the following command:

ssh -T git@github.com

The first time you connect to GitHub via SSH, you may see a message like this:

The authenticity of host 'github.com (20.201.28.151)' can't be established.
ED25519 key fingerprint is SHA256:+AiB3wcvD6FuJGhblZimn/zMBA0zZNSvHakb4evDOkU.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? 

Type yes

The authenticity of host 'github.com (20.201.28.151)' can't be established.
ED25519 key fingerprint is SHA256:+AiB3wcvD6FuJGhblZimn/zMBA0zZNSvHakb4evDOkU.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'github.com' (ED25519) to the list of known hosts.
Hi alexcalaca! You've successfully authenticated, but GitHub does not provide shell access.

Type yes and press Enter to continue. GitHub will now be added to your list of known hosts.

Success

If you see the message confirming your authentication, congratulations! You’ve successfully set up SSH for GitHub, which means you can now use SSH-based commands to interact with your repositories.

Hi alexcalaca! You've successfully authenticated, but GitHub does not provide shell access.

Output

Image Success

Done


This content originally appeared on DEV Community and was authored by Alexandre Calaça


Print Share Comment Cite Upload Translate Updates
APA

Alexandre Calaça | Sciencx (2024-11-05T02:42:24+00:00) How to Set Up SSH Keys for GitHub on PopOs or Ubuntu: A Beginner’s Guide. Retrieved from https://www.scien.cx/2024/11/05/how-to-set-up-ssh-keys-for-github-on-popos-or-ubuntu-a-beginners-guide/

MLA
" » How to Set Up SSH Keys for GitHub on PopOs or Ubuntu: A Beginner’s Guide." Alexandre Calaça | Sciencx - Tuesday November 5, 2024, https://www.scien.cx/2024/11/05/how-to-set-up-ssh-keys-for-github-on-popos-or-ubuntu-a-beginners-guide/
HARVARD
Alexandre Calaça | Sciencx Tuesday November 5, 2024 » How to Set Up SSH Keys for GitHub on PopOs or Ubuntu: A Beginner’s Guide., viewed ,<https://www.scien.cx/2024/11/05/how-to-set-up-ssh-keys-for-github-on-popos-or-ubuntu-a-beginners-guide/>
VANCOUVER
Alexandre Calaça | Sciencx - » How to Set Up SSH Keys for GitHub on PopOs or Ubuntu: A Beginner’s Guide. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/11/05/how-to-set-up-ssh-keys-for-github-on-popos-or-ubuntu-a-beginners-guide/
CHICAGO
" » How to Set Up SSH Keys for GitHub on PopOs or Ubuntu: A Beginner’s Guide." Alexandre Calaça | Sciencx - Accessed . https://www.scien.cx/2024/11/05/how-to-set-up-ssh-keys-for-github-on-popos-or-ubuntu-a-beginners-guide/
IEEE
" » How to Set Up SSH Keys for GitHub on PopOs or Ubuntu: A Beginner’s Guide." Alexandre Calaça | Sciencx [Online]. Available: https://www.scien.cx/2024/11/05/how-to-set-up-ssh-keys-for-github-on-popos-or-ubuntu-a-beginners-guide/. [Accessed: ]
rf:citation
» How to Set Up SSH Keys for GitHub on PopOs or Ubuntu: A Beginner’s Guide | Alexandre Calaça | Sciencx | https://www.scien.cx/2024/11/05/how-to-set-up-ssh-keys-for-github-on-popos-or-ubuntu-a-beginners-guide/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.