Generate GitLab SSH Keys & setup SSH on GitLab |Video upload date:  · Duration: PT14M32S  · Language: EN

Step by step guide to generate SSH keys and configure SSH on GitLab for secure push and pull access and painless authentication

If your Git pushes feel like begging for attention every time you type a password you are doing it wrong. Use SSH keys for GitLab to get secure, password free pushes and pulls. This guide walks through checking for existing keys generating a modern ed25519 key adding it to the SSH agent and registering the public key with GitLab while dropping a few snarky comments along the way.

Check for existing SSH keys

First avoid trashing a key that already works for other servers. Peek inside your SSH folder to see what is already there.

ls -al ~/.ssh

Look for files like id_ed25519 and id_ed25519.pub or id_rsa and id_rsa.pub. If you find a pair you already use you can skip key generation and just add the private key to your agent later.

Generate a new SSH key pair

Use a modern algorithm and don't pick RSA unless you have a boring reason. Run this command and follow the prompts for file name and passphrase. A passphrase is optional but recommended for real security.

ssh-keygen -t ed25519 -C 'your.email@example.com'

The command will ask where to save the key. Press Enter to accept the default like ~/.ssh/id_ed25519 or give a descriptive file name if you want multiple keys for different machines. Remember the private key must stay secret. The public key is what you will paste into GitLab.

Add the private key to the SSH agent

Typing your passphrase every time is fine if you enjoy suffering. The SSH agent caches the unlocked key so Git can do its thing without constant nagging.

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

If the agent fails to start your system might already manage keys for you especially on macOS or some Linux desktop environments. If so just add the key with ssh add and move on.

Copy and add your public key to GitLab

Now grab the public key text. It is a single long line that starts with the key type and ends with your comment or email.

cat ~/.ssh/id_ed25519.pub

Copy the entire line and then open GitLab in your browser. Go to your user settings and find SSH Keys. Paste the key into the key field give it a useful title like Workstation or Laptop and save. You do not need admin rights to add personal keys to your account.

Test the SSH connection

Make sure GitLab recognizes your shiny new key. Run this to test the connection and accept the host fingerprint when prompted.

ssh -T git@gitlab.com

A successful response will mention your GitLab username or a welcome message. If it complains about permission denied then something on the private key side needs fixing.

Quick troubleshooting and tips

  • Permissions matter. If your private key is too open fix it with chmod 600 ~/.ssh/id_ed25519.
  • If you have multiple keys you can use an SSH config file to tell SSH which key to use for GitLab. A minimal example in ~/.ssh/config would list a Host entry for gitlab.com and an IdentityFile pointing at the appropriate private key.
  • If a repository still asks for credentials use the SSH remote that GitLab shows in the project web UI rather than an HTTPS remote. The web UI will give the correct SSH clone URL to use.
  • Want to rotate keys or revoke a lost laptop Make a new key pair and remove the old public key from your GitLab SSH Keys page.

That is all. You now have key based authentication for Git operations which eliminates password prompts and is more secure than typing credentials into the void. Go commit something meaningful or at least amusing.

I know how you can get Azure Certified, Google Cloud Certified and AWS Certified. It's a cool certification exam simulator site called certificationexams.pro. Check it out, and tell them Cameron sent ya!

This is a dedicated watch page for a single video.