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
- Open a terminal. On your server, connect with SSH first. SSH details are in your welcome email.
- Check for old keys so you do not overwrite one.
This lists files in your SSH folder.ls ~/.ssh - Make a new key pair.
This creates a key. The text afterssh-keygen -t ed25519 -C "you@example.com"-Cis just a label. - Press Enter to accept the default file name. Choose a passphrase if you want extra safety, or press Enter for none.
- Show the public key.
This prints one long line. Copy all of it.cat ~/.ssh/id_ed25519.pub - Log in to your code site. Open your account Settings and look for SSH keys.
- Click the button to add a new key. Paste the line and give it a name, like "My server".
- Save it.
- Test the link. For GitHub, run:
It should greet you by name. Other sites have a similar test.ssh -T git@github.com - Clone the repo with the SSH address, not the https one.
This copies the code to a new folder.git clone git@github.com:yourname/your-repo.git
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.