ServicesAboutGet Started
Windows 11SSHGitLab

Setting Up an SSH Key on Windows 11

Generate an ed25519 SSH keypair on Windows 11 and add it to GitLab for secure, passwordless git operations — no more typing credentials on every clone, push, or pull.

SSH keys can be used for more than just SSH connections to servers. They can also be used to authenticate with services like GitLab and GitHub for git operations (clone, push, pull) without entering a password. This guide walks through generating an ed25519 SSH keypair on Windows and adding it to your GitLab account.


Step 1 — Generate the SSH Keypair

Open a terminal window to your user profile directory. The fastest method is to hit the start button or search bar and type terminal and press Enter.

Windows 11 search bar with terminal typed
Windows Terminal opened to user profile directory

Run the following command:

powershell
ssh-keygen -t ed25519 -C "Work Computer"
  • -t ed25519 specifies the key algorithm (ed25519 is modern, fast, and more secure than RSA)
  • -C "Work Computer" adds a comment to identify which machine the key belongs to — update this to something meaningful (e.g., "Jared Desktop", "Dev Laptop")

When prompted:

  1. For a file location, press Enter to accept the default (C:\Users\<username>\.ssh\id_ed25519)
  2. For a passphrase, press Enter for no passphrase
  3. To confirm the passphrase, press Enter again

The key pair is now created. You will see output showing the key fingerprint and a randomart image.

SSH keygen output showing fingerprint and randomart
💡

What was created: Two files in your C:\Users\<username>\.ssh\ directory:

  • id_ed25519 — your private key (never share this)
  • id_ed25519.pub — your public key (this is what you add to GitLab)

Step 2 — Copy the Public Key

Run the following command to display your public key:

powershell
Get-Content "$env:USERPROFILE\.ssh\id_ed25519.pub"
Terminal output showing the public key contents

Copy the entire output — it will look something like:

text
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI... Work Computer
💡

The -C comment you used during key generation appears at the end of the public key. This is how GitLab will auto-name the key when you paste it.


Step 3 — Add the Key to GitLab

Log into GitLab. Click your avatar (top-right) → Edit profile.

GitLab avatar dropdown — Edit profile option

In the left sidebar, go to Access TokensSSH keys.

GitLab sidebar — SSH keys navigation

Click Add new key.

Add new key button in GitLab SSH keys page

Paste your public key into the Key field. The Title will auto-populate from the -C comment you set during key generation. Optionally set an Expiration date, then click Add key.

GitLab Add SSH key form with key pasted and title auto-populated

Step 4 — Test the Connection

Run the following command to verify the key is working:

powershell
ssh -T git@gitlab.com

If this is your first time connecting, you will be asked to confirm the host fingerprint — type yes.

A successful connection will display:

text
Welcome to GitLab, @YourUsername!
Terminal showing successful SSH connection to GitLab

Step 5 — Clone a Repository Using SSH

When cloning a repository, use the SSH URL (not HTTPS). You can find the SSH clone URL on any GitLab project page by clicking the Code dropdown and selecting Clone with SSH.

GitLab project page — Clone with SSH URL
powershell
git clone git@gitlab.com:YourOrg/your-project.git
Terminal showing a successful git clone via SSH

Troubleshooting

"Permission denied (publickey)"

  • Verify the key exists:
    powershell
    Test-Path "$env:USERPROFILE\.ssh\id_ed25519"
  • Verify the public key was added to GitLab (Step 3)
  • Verify the ssh-agent is running:
    powershell
    Get-Service ssh-agent
  • If the ssh-agent service is disabled, enable and start it:
    powershell
    Set-Service ssh-agent -StartupType Automatic
    Start-Service ssh-agent
    ssh-add "$env:USERPROFILE\.ssh\id_ed25519"

"Host key verification failed"

This means you haven't accepted GitLab's host fingerprint yet. Run ssh -T git@gitlab.com and type yes when prompted.

powershell
ssh -T git@gitlab.com

Multiple SSH Keys

If you have multiple keys for different services, create a config file at C:\Users\<username>\.ssh\config:

text
Host gitlab.com
    HostName gitlab.com
    User git
    IdentityFile ~/.ssh/id_ed25519
💡

If you have multiple keys for GitLab, you will have to manage things yourself. You can alias the host in your config file to use a different key, but then you will have to know and understand how to clone it using that alias. That process is beyond the scope of this guide.