Setting Up SSH Connection between Ubuntu 22 and GitHub: A Step-by-Step Guide

To make an SSH connection between Ubuntu 22 and GitHub, you can follow these steps:

1. Generate an SSH key pair: run the following command to generate an SSH key pair:

 

ssh-keygen -t ed25519 -C "[email protected]"

 

Replace `”[email protected]”` with your actual email address. You can also choose a different key type (e.g., RSA) if you prefer.

 

2. Save the key pair: The command will prompt you to choose a location to save the key pair. Press Enter to accept the default location (`/home/your_username/.ssh/id_ed25519`).

 

3. Set a passphrase (optional): You can choose to set a passphrase for your SSH key pair. It adds an extra layer of security but is not mandatory. If you want to set a passphrase, enter it when prompted. Otherwise, press Enter twice to leave it blank.

 

4. Start the SSH agent: Run the following command to start the SSH agent:

 

eval "$(ssh-agent -s)"

 

5. Add your private key to the SSH agent: Use the following command to add your private key to the SSH agent:

ssh-add ~/.ssh/id_ed25519

If you chose a different file name or location in step 2, adjust the command accordingly.

 

6. Copy your public key: Run the following command to display your public key:

 

cat ~/.ssh/id_ed25519.pub

 

The output should be a long string starting with `ssh-ed25519`. Copy the entire key to your clipboard.

 

7. Add the SSH key to your GitHub account: Open your GitHub account settings in a web browser and go to the “SSH and GPG keys” section. Click on “New SSH key” or “Add SSH key” and give it a meaningful title. Paste the key you copied in the previous step into the “Key” field and click “Add SSH key” or “Save”.

 

8. Test the SSH connection: To test the SSH connection, run the following command in the terminal:

 

ssh -T [email protected]

 

If everything is set up correctly, you should see a message like:

 

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

 

Replace `username` with your GitHub username.

 

That’s it! You’ve successfully set up an SSH connection between Ubuntu 22 and GitHub. From now on, you can use SSH URLs (e.g., `[email protected]:user/repo.git`) to interact with GitHub repositories without entering your username and password each time.

 

All Commands:

cd ~/.ssh
ssh-keygen -t ed25519 -C "[email protected]"
id_ed25519
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
cat ~/.ssh/id_ed25519.pub
ssh -T [email protected]

References: 

https://docs.github.com/en/authentication/connecting-to-github-with-ssh/about-ssh 

Leave a Comment

Your email address will not be published. Required fields are marked *