How to set an SSH connection to GitHub from Ubuntu
Master SSH key management on Ubuntu, secure multiple GitHub accounts, projects, and servers with ease.
If you’re tired of typing your GitHub password every time you push code or just want a more secure way to interact with your repositories, SSH keys are the answer. Unlike HTTPS, which requires constant authentication, SSH establishes a secure, password-less connection between your Ubuntu machine and GitHub, making your workflow faster and safer.
In this guide, learn how to generate an SSH key, add it to GitHub, and use SSH with GitHub actions. By the end, you’ll be able to clone, push, and pull repositories without ever entering a password again.
How to Set Up SSH Connection to GitHub from Ubuntu
Step 1: Check for Existing SSH Keys
Before generating a new key, check if you already have one:
ls ~/.ssh
If you see files like "id_rsa" and "id_rsa.pub", you already have a key pair, so just skip to Step 4.

Step 2: Generate a new SSH Key
Run this command (replace the email with your GitHub email):
ssh-keygen -t rsa -b 4096 -C "youremail@example.com"
The command above saves your SSH with the default name. To customize the name of your SSH key, enter :
ssh-keygen -t rsa -b 4096 -C "youremail@gmail.com" -f ~/.ssh/id_rsa_custom-name
You'll be asked to enter a passphrase. You can hit the Enter key if you don't want to have to enter a passphrase whenever you need to use SSH, but it is recommended to add a passphrase for extra security.

Step 3: Copy Your Public Key
Display and copy your public key:
cat ~/.ssh/id_rsa.pub
Select and copy the entire output (starts with ssh and ends with your email). If you set up your key to use a custom name like I did, don't forget to add the ".pub" to the end of the name. The ".pub" tells it to return the public key, which GitHub needs.

Step 4: Add the SSH Key to GitHub
- Go to your GitHub Settings and click on SSH and GPG Keys on the left panel.
- Click New SSH Key.

- Give it a title and paste your public key. Then click "Add SSH Key".

Step 5: Test the Connection
Verify everything works:
ssh -T git@github.com
You should see: "Hi (username), You’ve successfully authenticated, but GitHub does not provide shell access."

Step 7: Clone a Repository (Optional)
Now that you have connected to GitHub, you can clone repos using SSH URLs instead of HTTPS:
git clone [SSH URL]

Conclusion
That’s it. You’ve now set up a secure SSH connection between your Ubuntu machine and GitHub. Now you can easily perform GitHub actions like cloning, pulling, etc., with ease. There will be no more password prompts, just smooth, encrypted Git operations.
Keep your keys secure, because that is your access to your account, and you won't want it to get out of your hands. To be safe, always use a passphrase for your SSH keys.
Image Credit: Oyinebiladou Omemu/Techloy.com