Lesstep
GitLab.com and Self-Managed · Git over SSH · Checked November 22, 2026

GitLab SSH: "git@gitlab.com: Permission denied (publickey)"

SSH reached the GitLab server and the server did not accept any key your computer offered. Either the key GitLab should know is not on your GitLab account, or SSH is not offering it: it offers the default key files and the keys in your agent, not the file you had in mind. Three commands find which: ssh-add -l for what the agent holds, ssh -Tvvv for what SSH tries, and ssh -i KEY -o IdentitiesOnly=yes -T to offer exactly one key. The message names the host it came from, so a Self-Managed server and gitlab.com are told apart.

The message

Checked November 22, 2026, with no key offered, on GitLab.com and on its port-443 SSH host:

git@gitlab.com: Permission denied (publickey).
git@altssh.gitlab.com: Permission denied (publickey).

The part before the colon is the user and host SSH connected to. GitLab's SSH page tests a connection with ssh -T git@gitlab.com (or git@gitlab.example.com for GitLab Self-Managed and Dedicated; an administrator can change the default git username) and expects Welcome to GitLab, <username>!. Anything else is this page's problem.

To replace an expired token in one place: Merge Request (MR) Review Inbox for GitLab, a plugin for JetBrains IDEs, says on a 401 that the token expired, was revoked or is from another GitLab instance, and keeps the token in the IDE's password safe, so replacing it there is the only change.

GitLab's list of causes

From GitLab's Troubleshooting SSH:

  1. The public key was not added to your GitLab account (common for new users or new machines).
  2. The key type is not supported, or it includes headers GitLab does not recognize.
  3. With several local SSH keys, the wrong private key is used. SSH defaults to ~/.ssh/id_rsa or id_ed25519, and you might need to define which key to use.
  4. The private key is not accessible on your local device.
  5. Local permissions are wrong: the private key should be 600 and the .ssh directory 700.
  6. The key is not loaded in ssh-agent (common after a reboot or in a new terminal session).

The page gives ssh -Tvvv git@gitlab.example.com to debug, but no command for causes 3 and 6. The steps below are those commands, from the OpenSSH manual pages.

Step 1: what the agent holds

ssh-add -l

Per the manual, this lists the fingerprints of all identities the agent holds. Compare them with the SSH keys listed on your GitLab account. If the agent holds nothing, or cannot be reached (on one Windows computer on November 22, 2026, ssh-add -l printed "Could not open a connection to your authentication agent."), load the key. Plain ssh-add adds the default files ~/.ssh/id_rsa, ~/.ssh/id_ecdsa, ~/.ssh/id_ecdsa_sk, ~/.ssh/id_ed25519, ~/.ssh/id_ed25519_sk and ~/.ssh/id_mldsa44_ed25519; for a key with another name, give the file:

ssh-add ~/.ssh/KEYFILE

Step 2: what SSH tries

ssh -Tvvv git@gitlab.com

Without an IdentityFile setting, ssh tries those same default files, in that order (ssh_config). The debug output has a line for each: with OpenSSH 10.2, debug1: identity file ... type -1 and debug1: no identity pubkey loaded from ... for a file that is not there, and it ends with Authentications that can continue: publickey before the denial. A key named something else, such as id_gitlab, is never tried unless it is in the agent or configured. That is cause 3 in GitLab's list.

Step 3: offer exactly one key

ssh -i ~/.ssh/KEYFILE -o IdentitiesOnly=yes -T git@gitlab.com

IdentitiesOnly=yes makes ssh use only the configured identity files and ignore other identities offered by an agent (ssh_config). If this prints Welcome to GitLab, the key is on your account and the problem was which key SSH chose; if it still says Permission denied (publickey), the key is not on the account GitLab expects, is of an unsupported type, or has wrong permissions (causes 1, 2 and 5). GitLab's key types: ED25519 (preferred, OpenSSH 6.5 or later), ED25519_SK and ECDSA_SK (OpenSSH 8.2 or later on both sides), RSA (at least 4096 bits recommended, 8192 at most) and ECDSA.

Step 4: keep it in ~/.ssh/config

When step 3 works, put the choice in ~/.ssh/config so Git uses it too:

Host gitlab.com
  HostName gitlab.com
  User git
  IdentityFile ~/.ssh/KEYFILE
  IdentitiesOnly yes

For a Self-Managed server, use its host name for Host and HostName. Host limits the lines below it to matching host names, and IdentityFile names the key to try.

GitLab merge requests and pipelines in IntelliJ IDEA

Lesstep makes two plugins for JetBrains IDEs 2024.1 or later that read GitLab with read_api and change things with api: Merge Request (MR) Review Inbox for GitLab and Pipelines and Jobs Inbox for GitLab CI. When GitLab refuses the token with 401 while they read, they say that the token expired, was revoked or is from another GitLab instance, show GitLab's own description, and offer to open their settings, which have a link to GitLab's form with the name and scope filled in (GitLab 16.7 or later). The token is kept in the IDE's password safe, so replacing it there is the only change. Reading is free; approving, commenting and merging, or retrying, cancelling and running pipelines, are Pro (US$1.50 a month, with a 30-day trial).

Get it on JetBrains Marketplace

GITLAB is a trademark of GitLab Inc.; IntelliJ IDEA is a trademark of JetBrains s.r.o. This page is not affiliated with or endorsed by GitLab Inc. or JetBrains.

More: GitLab "HTTP Basic: Access denied" · git clone "SSL certificate problem" with GitLab · GitLab 401 "invalid_token" · GitLab 404 "Project Not Found" · GitLab "insufficient_scope" · GitLab push rejected by a pre-receive hook · GitLab merge request plugins for IntelliJ IDEA, compared · 日本語