How to create SSH key and use for GitLab?

SSH is a better way to connect to Git servers than HTTPS, because you do not enter your password every time. An SSH key is a pair: a private key stays on your computer and a public key is added to GitLab.

  • Open the terminal (Git Bash or PowerShell on Windows).
  • Create a key: ssh-keygen -t ed25519 -C "your-email@example.com". Press Enter to accept the default file, and set a passphrase if you like. (For old systems use ssh-keygen -t rsa -b 4096 -C "your-email@example.com".)
  • Show the public key: cat ~/.ssh/id_ed25519.pub and copy the full line.
  • In GitLab go to Preferences, then SSH Keys, paste the key, write a title and click Add key.
  • Test the connection: ssh -T git@gitlab.com.
  • Clone with the SSH URL, like git clone git@gitlab.com:username/project.git.

The same steps work for GitHub (Settings, then SSH and GPG keys). Detailed steps are in Git SSH Key.


Learn more about the similar topics:
Tutorials
Git Introduction
Version Control System
Install Git
Git Configuration
Git Workflow
Git SSH Key
Git and GitHub
Exercises & Assignments
Create a Git repository and make your first commit
Interview Questions & Answers
What is Git?
Why SSH key is used in Git?
How to create SSH key and use for GitLab?
What is the difference between Git and GitHub?
What is a repository in Git?