In your tech journey, you will definitely come across SSH multiple times, so it’s in your best interest to understand “the what” and “the why.”
SSH (Secure Shell) is a secure protocol used to facilitate communication between computers and servers through the terminal. It is commonly preferred because it is secure, fast, and hard to compromise without the correct credentials.
SSH is widely used for:
- Secure file transfers
- System administration
- Remote server access
- Authenticating Git operations (push and pull requests)
In this guide, we’ll focus on using SSH keys to securely connect your Ubuntu machine to GitHub, allowing you to push and pull code without repeatedly entering your username and password.
Prerequisites
Before you begin, ensure you have the following:
- A PC running Ubuntu
- Git installed 👉 Refer to my previous article: https://dev.to/k1int/installing-and-setting-up-git-on-ubuntu-beginners-guide-5bk0
- SSH installed
- Basic terminal knowledge
Open your terminal using Ctrl + Alt + T.
Step 1: Confirm SSH Installation
Run the command below:
ssh -V
If SSH is installed, you should see output similar to:
OpenSSH_9.6p1 Ubuntu-3ubuntu13.14, OpenSSL 3.0.13 30 Jan 2024
If SSH Is Not Installed
Install it using:
sudo apt update
sudo apt install openssh-server
Check if SSH is running:
sudo systemctl status ssh
Enable SSH to start on boot (recommended):
sudo systemctl enable ssh
Step 2: Check for Existing SSH Keys
Run:
ls -a ~/.ssh
If keys already exist, you should see something similar to:
. .. authorized_keys id_ed25519 id_ed25519.pub known_hosts known_hosts.old
id_ed25519 → Private key (keep this secret ❗)
id_ed25519.pub → Public key (shared with GitHub)
Step 3: Generate an SSH Key (If You Don’t Have One)
If no keys are found, generate one:
ssh-keygen -t ed25519 -C "your_email@example.com"
When prompted:
Press Enter to accept the default location
Optionally add a passphrase for extra security
Step 4: Start the SSH Agent and Add Your Key
Start the SSH agent:
eval "$(ssh-agent -s)"
Add your SSH private key:
ssh-add ~/.ssh/id_ed25519
Confirm the key is added:
ssh-add -l
Step 5: Add the SSH Key to Your GitHub Account
Copy Your Public Key
cat ~/.ssh/id_ed25519.pub
Copy the entire output.
Add the Key on GitHub
-Log in to GitHub
-Click your profile picture → Settings
-Navigate to SSH and GPG keys
-Click New SSH key
Add:
-Title: e.g. Ubuntu Laptop
-Key: Paste the copied public key
-Click Add SSH key
Step 6: Test the SSH Connection
Verify the setup:
ssh -T git@github.com
If successful, you should see:
Hi username! You've successfully authenticated, but GitHub does not provide shell access.
Congratulations! Your Ubuntu machine is now securely connected to GitHub using SSH.
Conclusion
-SSH is more secure than HTTPS authentication
-No need to enter passwords when pushing or pulling code
-This setup is essential for professional Git workflows
What’s Next?
-In the next article, we’ll walk through:
-Initializing a Git repository
-Making commits
-Pushing and pulling changes from GitHub using SSH
Happy Coding!
Top comments (0)