Flash Sale:75% Off Hosting + Free DomainEnds in13h47m14sView Plans
Hostvento logoHostvento

Set Up Access to a Private Git Repository

This guide shows you how to let your server or computer download code from a private Git repository using an SSH key.

Website Management2 min read10 steps

What are these words?

Git is a tool that tracks changes in code. A repository (or repo) is a folder of code kept by Git. A private repo can only be seen by people you allow. Sites like GitHub, GitLab and Bitbucket host repos.

To prove who you are, you use an SSH key. It is a pair of files. The private key stays secret with you, like a house key. The public key goes to the code site, like a lock that only your key opens.

Steps

  1. Open a terminal. On your server, connect with SSH first. SSH details are in your welcome email.
  2. Check for old keys so you do not overwrite one.
    ls ~/.ssh
    This lists files in your SSH folder.
  3. Make a new key pair.
    ssh-keygen -t ed25519 -C "you@example.com"
    This creates a key. The text after -C is just a label.
  4. Press Enter to accept the default file name. Choose a passphrase if you want extra safety, or press Enter for none.
  5. Show the public key.
    cat ~/.ssh/id_ed25519.pub
    This prints one long line. Copy all of it.
  6. Log in to your code site. Open your account Settings and look for SSH keys.
  7. Click the button to add a new key. Paste the line and give it a name, like "My server".
  8. Save it.
  9. Test the link. For GitHub, run:
    ssh -T git@github.com
    It should greet you by name. Other sites have a similar test.
  10. Clone the repo with the SSH address, not the https one.
    git clone git@github.com:yourname/your-repo.git
    This copies the code to a new folder.
Warning: Never share the file without .pub at the end. That is your private key. Anyone who has it can use your account.

If you have several keys

Create a file ~/.ssh/config and name which key goes with which site.

Host github.com
  IdentityFile ~/.ssh/id_ed25519

This tells SSH to use that key for GitHub.

Tip: Some sites also offer deploy keys for one repo only. They are good for servers, because they limit the damage if lost.

Quick recap

  • Make an SSH key pair with ssh-keygen.
  • Add the public key (.pub) to your code site.
  • Keep the private key secret.
  • Test the connection, then clone with the SSH address.