GitLab SSH "Permission denied (publickey)": causes and fixes

By Melih Toksari, developer of MergeBell · Updated · 5 min read

Short answer

Permission denied (publickey) means GitLab's SSH server accepted none of the keys your SSH client offered. Run ssh -T git@gitlab.com: "Welcome to GitLab, @username!" means a key works and names the account it belongs to. If it fails, add your public key under Edit profile › Access › SSH keys with a usage type that includes Authentication, check that the key hasn't expired, load it into ssh-agent or point ~/.ssh/config at it with IdentityFile, and keep the private key at permissions 600. DSA keys are forbidden by default. If your network blocks port 22, GitLab.com also answers on altssh.gitlab.com, port 443.

git clone, git pull or git push over SSH stops with this:

git@gitlab.com: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

GitLab’s SSH server turned down every key your SSH client offered, or the client offered none. GitLab didn’t get as far as your project. Here is how to find which key is wrong in GitLab 19.5, and fix it.

Test the connection first

ssh -T git@gitlab.com

On your own GitLab, use its host name, without a project path: ssh -T git@gitlab.example.com.

You see It means
Welcome to GitLab, @your-username! The key works. The problem is the remote, the project or your access: see SSH works, Git doesn’t.
Welcome to GitLab, @someone-else! The key works, but it belongs to another account, or it’s a deploy key that account added. GitLab knows you by your key alone.
Permission denied (publickey). No key you offered is one GitLab accepts. Read on.
git@gitlab.example.com's password: A self-managed server that also allows passwords: SSH found no key GitLab accepts. There’s no password to give: fix the key.
Could not resolve hostname The host name is wrong, often because it includes the project path, like gitlab.com:group/project.git.
connect to host gitlab.com port 22: Connection timed out Your network blocks port 22: see port 22 blocked.

To see which keys SSH tries, add -v. Each Offering public key: line names one; check that the key you added to GitLab is among them.

Fix the key

The public key isn’t on your account

  1. Look for a key pair in ~/.ssh: a private key such as id_ed25519 and its public half, id_ed25519.pub. If there’s none, make one with ssh-keygen -t ed25519 -C "work laptop".
  2. Copy the contents of the .pub file: the whole line, starting with ssh-ed25519 (or ssh-rsa, ecdsa-sha2-…).
  3. In GitLab, select your avatar, then Edit profile › Access › SSH keys › Add new key, and paste it.
  4. Keep the Usage type at Authentication & Signing, or choose Authentication. A key added for Signing only can sign commits but never signs you in.
  5. Check the Expiration date. Once it passes, the key no longer works for Git. GitLab emails you seven days before, and on the day.

SSH offers a different key

SSH tries its default key files, such as id_ed25519 and id_rsa, plus any keys loaded in ssh-agent. If your GitLab key has another name or lives elsewhere, point SSH at it in ~/.ssh/config:

Host gitlab.com
  PreferredAuthentications publickey
  IdentityFile ~/.ssh/gitlab_ed25519
  IdentitiesOnly yes

IdentitiesOnly yes makes SSH offer only that key. Without it, an agent holding many keys can hit a server’s limit on attempts, and SSH stops with Too many authentication failures (lowercase on GitLab.com).

For two GitLab accounts on one instance, give each its own Host alias with its own IdentityFile, like Host work.gitlab.com with Hostname gitlab.com, and use the alias in the remote: git@work.gitlab.com:group/project.git.

The key isn’t loaded

After a reboot, or in a new terminal, a key with a passphrase may not be in the agent yet:

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

ssh-add -l lists the keys the agent holds.

File permissions are too open

SSH ignores a private key that other users can access, with a WARNING: UNPROTECTED PRIVATE KEY FILE! banner. GitLab’s docs ask for 600 on the private key and 700 on the folder:

chmod 700 ~/.ssh
chmod 600 ~/.ssh/id_ed25519

The key type isn’t allowed

  • DSA keys are forbidden by default on GitLab.com and GitLab Self-Managed.
  • RSA keys can be at most 8192 bits; GitLab recommends at least 4096.
  • Administrators of GitLab Self-Managed can forbid other types or set minimum lengths. A key that no longer meets the rules shows a warning icon in your SSH keys list. It still passes ssh -T, but Git answers “Your SSH key type is forbidden. Must be …” or “Your SSH key must be at least 4096 bits.”

Make an ED25519 key instead, unless your system can’t use it: some FIPS systems don’t fully support ED25519.

On Windows

WSL and Git for Windows have different home folders, /home/<user> and C:\Users\<user>, so a key made in one isn’t seen by the other. Copy the .ssh folder across, or make a key in each. With Windows 11’s OpenSSH, check that the HOME variable points at your user folder.

GitLab won’t take the key

GitLab says Why
Fingerprint sha256 has already been taken The public key is already on GitLab: on your account (check the list), on another account, or as a deploy key. A key maps to one identity: if it isn’t already yours, make a new pair.
Key cannot be used because it belongs to a compromised private key. Stop using this key and generate a new one. GitLab blocks keys whose private half is publicly known. Make a new pair.
Key has expired The expiration date you entered is in the past.

SSH works, Git doesn’t

  • The remote isn’t SSH. git remote -v shows an https:// address, so Git never uses your key. Switch it with git remote set-url origin git@gitlab.com:group/project.git, or fix the HTTPS sign-in: HTTP Basic: Access denied.
  • The account can’t see the project. GitLab answers “The project you were looking for could not be found or you don’t have permission to view it.” Check the path and that the account in the welcome message is a member.
  • The account can’t push. “You are not allowed to push code to this project.” means your role can’t push; for a protected branch, see not allowed to push to a protected branch. A deploy key without write access gets “This deploy key does not have write access to this project.”
  • Your GitLab.com group enforces SSO for Git. With Enforce SSO-only authentication for Git and Dependency Proxy activity for this group turned on, you need an active SSO session, on any device, before you can pull or push over SSH. Sign in through the group’s SSO in a browser first.

Port 22 blocked

Some networks only let HTTPS out. GitLab.com also accepts SSH on altssh.gitlab.com, port 443:

Host gitlab.com
  Hostname altssh.gitlab.com
  User git
  Port 443
  PreferredAuthentications publickey
  IdentityFile ~/.ssh/id_ed25519

Your remotes keep git@gitlab.com:…; SSH sends them to port 443. On GitLab Self-Managed, ask your administrator: the instance may use another host or port, and even another user than git.

The first time you connect to a host, SSH asks you to confirm its fingerprint. Compare it with GitLab.com’s published fingerprints, or your instance’s /help/instance_configuration page, before you answer yes. Host key verification failed means SSH couldn’t confirm the host: the saved fingerprint doesn’t match, or, in a CI job, none is saved. After checking the new fingerprint, remove a stale entry with ssh-keygen -R gitlab.com (with port 443: ssh-keygen -R '[altssh.gitlab.com]:443').

On your phone

MergeBell doesn’t use Git or SSH. It talks to GitLab’s API, signed in on GitLab’s own page on gitlab.com or with a personal access token on a self-managed GitLab. An SSH problem on your laptop doesn’t stop you reviewing, approving and merging from your phone, and nothing in the app needs your SSH key.

Frequently asked questions

What does "Permission denied (publickey)" mean on GitLab?

GitLab's SSH server didn't accept any key your SSH client offered, or the client offered none. Usually the public key isn't on your GitLab account, SSH is using a different private key, the key has expired, or it was added for signing only. GitLab never got as far as checking your project.

How do I test my SSH key with GitLab?

Run ssh -T git@gitlab.com, or git@ followed by your own instance's host name. "Welcome to GitLab, @username!" means the key works, and names the account it belongs to. Add -v to see which keys SSH offers.

Why does ssh -T work but git push still fails?

The key signs in, but as an account that can't reach the project, or the remote isn't using SSH at all. Check that the welcome message names the right account, and that git remote -v shows a git@ address. A project the account can't see answers "The project you were looking for could not be found or you don't have permission to view it.", and a role that can't push answers "You are not allowed to push code to this project."

Which SSH key types does GitLab accept?

ED25519 (the recommended type), ED25519_SK, ECDSA_SK, RSA and ECDSA. GitLab recommends RSA keys of at least 4096 bits, and the maximum is 8192. DSA keys are forbidden by default on GitLab.com and GitLab Self-Managed, and an administrator can restrict other types or set minimum lengths. A key that breaks those rules shows a warning icon in your SSH keys list, and Git refuses it with "Your SSH key type is forbidden" or a minimum-length message.

How do I use SSH with GitLab when port 22 is blocked?

On GitLab.com, connect to altssh.gitlab.com on port 443: add a Host gitlab.com block to ~/.ssh/config with Hostname altssh.gitlab.com, User git and Port 443. Your remotes keep their git@gitlab.com addresses. On GitLab Self-Managed, ask your administrator which SSH host and port to use.

Sources

Checked against these pages on 1 November 2026. GitLab changes quickly — if something here no longer matches, tell us and we will fix it.

Do this from your phone with MergeBell

Free for the whole review loop: the To-Do inbox, diffs and line comments, approve and merge, pipelines with retry, and push alerts for your To-Dos. Works with gitlab.com and self-managed GitLab 16.0+.

Get MergeBell for iPhoneGet MergeBell for Android

On the App Store for iOS 26 or later and on Google Play for Android 12 or later. An independent app, not affiliated with GitLab Inc.