Private repositories on GitHub require authentication. On Ubuntu, this is conveniently done through SSH keys, which eliminates the need for constant login and password entry and enhances security.

🔑 Step 1: Generating an SSH Key

Open the terminal and execute:

ssh-keygen -t ed25519 -C "your_email@example.com"

If your version of OpenSSH does not support ed25519, use:

ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

When prompted for the save path, you can specify a file name, for example:

~/.ssh/github_private_repo

📋 Step 2: Adding the Key to the ssh-agent

Start the agent and add the key:

eval "$(ssh-agent -s)"
ssh-add ~/.ssh/github_private_repo

🌐 Step 3: Adding the Public Key to GitHub

  1. Copy the contents of the file ~/.ssh/github_private_repo.pub:
    cat ~/.ssh/github_private_repo.pub
  2. Go to GitHub → SettingsSSH and GPG keys.
  3. Click New SSH key, paste the key into the Key field, give it a name (for example, “Ubuntu Workstation”) and save.

⚙️ Step 4: Configuring the SSH Config

To ensure GitHub uses the correct key, create or edit the file ~/.ssh/config:

Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/github_private_repo
IdentitiesOnly yes

📥 Step 5: Cloning the Private Repository

Use the SSH address of the repository (you can copy it from the repository page on GitHub by selecting the SSH tab):

git clone git@github.com:username/private-repo.git

🛠️ Possible Issues

  • Permission denied (publickey) — check that the key is added to the ssh-agent and in GitHub.
  • If you have multiple keys, ensure that the correct IdentityFile is specified in ~/.ssh/config.
  • To access someone else's private repository, the owner must add you as a Collaborator or to the organization team.

✅ Conclusion

Now you can securely work with private GitHub repositories on Ubuntu using SSH keys. This will eliminate the need to enter a password and provide stable access to projects.