To set up SSH for accessing GitHub on your Ubuntu server, you can follow these steps. This assumes you have an existing SSH key pair; if not, you can generate one using ssh-keygen
. Here’s a step-by-step guide:
Step 1: Generate SSH Key Pair (if not already done)
If you don’t have an SSH key pair, you can generate one using the following command. Press Enter for the default file location and an empty passphrase when prompted.
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
Step 2: Add SSH Key to SSH Agent
Start the SSH agent and add your private key to it:
eval "$(ssh-agent -s)" ssh-add ~/.ssh/id_rsa
Step 3: Copy the SSH Public Key
Display your SSH public key:
cat ~/.ssh/id_rsa.pub
Copy the entire key.
Step 4: Add SSH Key to GitHub
- Go to your GitHub Settings.
- Navigate to “SSH and GPG keys” in the left sidebar.
- Click on “New SSH key” or “Add SSH key.”
- Add a title (e.g., “Ubuntu Server”).
- Paste your SSH key into the “Key” field.
- Click “Add SSH key.”
Step 5: Test Your SSH Connection
Test that your SSH connection to GitHub is working:
ssh -T git@github.com
If everything is set up correctly, you should see a message indicating successful authentication.
Step 6: Configure Git on Your Ubuntu Server
If you haven’t installed Git on your server, you can do so:
sudo apt update sudo apt install git
Then, configure Git with your username and email:
git config --global user.name "Your Name" git config --global user.email "your_email@example.com"
Step 7: Clone Repositories Using SSH
Now you can clone GitHub repositories using SSH:
git clone git@github.com:username/repository.git
Replace username
and repository
with your GitHub username and the name of the repository you want to clone.
That’s it! Your Ubuntu server is now set up to use SSH with GitHub.
What do you think?
Show comments / Leave a comment