Installing Git and Linking to GitHub on Ubuntu
Ubuntu developers frequently hit “permission denied” or “fatal: authentication failed” errors when contributing to GitHub repositories, usually due to incomplete SSH or Git configuration. Establishing a rock-solid link between your workstation and GitHub should be a day-one task.
1. Update APT Metadata
Always update your package index before touching development tools:
sudo apt update
Ubuntu’s repositories ship with upstream Git; rarely do you need a PPA unless you want bleeding-edge features or specific bugfixes.
2. Install Git
On Ubuntu 22.04 LTS, this yields Git v2.34.1 or similar:
sudo apt install git
git --version
# git version 2.34.1
If you need a newer version, see the upstream PPA:
sudo add-apt-repository ppa:git-core/ppa
sudo apt update
sudo apt install git
But for most workflows (merging, rebasing, branch management), the packaged version suffices.
3. Set Author Identity
Git ties each commit to a user/email. If this isn’t set, merges and CI jobs can get messy.
git config --global user.name "Jane Smith"
git config --global user.email "jsmith@example.com"
Audit with:
git config --list
Note: For multi-user systems or shared accounts, skip --global
and configure per-repository instead.
4. SSH Key Generation
Using SSH keys avoids repeated credential prompts and is required for secure GitHub access.
Generate a keypair (Ed25519 preferred since 2020):
ssh-keygen -t ed25519 -C "jsmith@example.com"
If your OpenSSH is older (<6.5), fallback to RSA 4096:
ssh-keygen -t rsa -b 4096 -C "jsmith@example.com"
Default save path: /home/$USER/.ssh/id_ed25519
Optional comment: use the email tied to your GitHub.
Caveat: On ephemeral VMs, be sure to export and persist .ssh/id_ed25519
off the system.
5. SSH-Agent Management
Load your key into the SSH agent to prevent session-based auth failures:
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
Trouble? If you hit Could not open a connection to your authentication agent.
, re-run agent start or check environment inheritance—tmux
/screen
sometimes break this.
6. Register Key with GitHub
- Display the public key:
cat ~/.ssh/id_ed25519.pub
- Copy the contents.
- In GitHub, go to
Settings → SSH and GPG Keys → New SSH key
. - Paste and give it a descriptive label (
Workstation-P441-Ubuntu
is better than "My laptop").
Note: If you rotate keys, old ones should be removed to avoid security drift.
7. Validate SSH Connectivity
Quick check:
ssh -T git@github.com
On first connect:
The authenticity of host 'github.com (140.82.121.4)' can't be established.
ED25519 key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
A successful handshake:
Hi jsmith! You've successfully authenticated, but GitHub does not provide shell access.
If you see:
Permission denied (publickey).
— re-check your ssh-add
output or GitHub key registration.
8. Clone a Repository (Practical Example)
Realistically, you often need to test full round-trip access. Replace jsmith
and infra-scripts
appropriately.
git clone git@github.com:jsmith/infra-scripts.git
Repository should clone without prompting for username/password. If asked, SSH isn’t set up right.
9. Non-Obvious Tip: Multiple GitHub Accounts
If you manage client and personal GitHub accounts, use an SSH config entry:
Host github-client
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519_client
Host github-personal
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519_personal
Then clone with:
git clone git@github-client:clientuser/repo.git
This avoids identity “collision” when managing multiple profiles.
Side Notes
- Performance: Large repositories with many submodules may require additional SSH configuration for performance or proxy tunneling.
- Known Issue: Some corporate firewalls block SSH/22. Use
ssh.github.com:443
as a workaround; details in GitHub’s SSH troubleshooting docs. - Alternatives: HTTPS-based auth with
gh
CLI is possible, but SSH is less brittle for CI/CD and automation environments.
Summary
Configuring Git and SSH keys on Ubuntu is essential groundwork for frictionless GitHub integration. Secure key management, user identity configuration, and connection validation are non-negotiable steps—failure here results in avoidable pipeline headaches and lost productivity. A little up-front rigor pays dividends under load.
Checklist Table:
Step | Command/Location | Gotcha |
---|---|---|
System update | sudo apt update | Skipping causes old packages |
Install git | sudo apt install git | May need PPA for new features |
Configure identity | git config --global ... | Wrong email breaks commit links |
Generate SSH keys | ssh-keygen -t ed25519 -C "<email>" | Use RSA if Ed25519 fails |
Add public key | GitHub → Settings → SSH keys | Remove old/compromised keys |
Test connection | ssh -T git@github.com | Proxy/firewall breaks here |
Clone repo | git clone git@github.com:user/repo.git | Prompts? SSH didn’t work |
Ready for automated deployment pipelines, pull-requests, or just pushing code at 2AM. SSH-based setup offers the highest reliability for cross-platform contributors.
If you need non-SSH alternatives, or hit edge-case errors, drop into the #git
or #ubuntu
IRC channels—chances are, someone solved it last week.