SSH "Permission denied (publickey,gssapi-keyex,gssapi-with-mic)": how to fix it

The server accepted your connection but refused every login method it offered. The names in brackets are the methods the server allows, and in practice the problem is nearly always public key authentication: wrong key, wrong username, or wrong file permissions. Run `ssh -vvv` to see which one it is.

Applies to:OpenSSH client and serverany; this exact list is the one some servers send, and the list depends on how that server is configured
On this page

What it means

This message means the SSH server answered, so the network path and port are fine. What failed is authentication: the server offered a few login methods, and none of them worked for you.

The words in brackets are the methods that server allows. Here that is publickey, plus gssapi-keyex and gssapi-with-mic, which are Kerberos-based methods. Unless your account is set up for Kerberos, the practical cause is public key authentication, so that is where to look first.

Symptoms and causes

You are likely dealing with this problem if:

  • user@host: Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
  • ssh -v shows keys being offered, or an identity file that does not exist, then ends with the error.

The usual causes, most common first:

Wrong or missing key on the client
The client is not offering the key whose public half is in the server's authorized_keys. Common reasons: wrong -i file, key not loaded in the agent, or ssh-add -l showing nothing.
Wrong username
The right name depends on the image, so check your provider's documentation for that image.
Wrong permissions or ownership on the server
StrictModes is on by default. sshd then refuses keys when the home directory, ~/.ssh or authorized_keys is writable by others or owned by the wrong user.
Private key permissions too open on the client
The ssh client ignores a private key that other users can access.
Public key missing or damaged in authorized_keys
The file may not exist, the key may have been pasted with a line break, or AuthorizedKeysFile may point somewhere else than you expect (default: .ssh/authorized_keys .ssh/authorized_keys2).
Algorithm mismatch
Since OpenSSH 8.8, ssh-rsa (RSA with SHA-1) signatures are off by default. An old client or server that only supports that fails against a modern peer.
Server configuration blocks the login
AllowUsers or DenyUsers excludes the account, PubkeyAuthentication no is set, the account is locked, or the home directory is encrypted or not mounted.

How to fix it

Work through these in order. They start with the quickest, safest checks and move to deeper repairs; stop as soon as the problem is gone.

1.Run ssh in verbose mode

Easy

It shows whether your key is even being sent, which tells you whether to look at the client or the server.

  1. Connect with maximum verbosity, using your real key path, user and host.
    Terminal
    ssh -vvv -i ~/.ssh/KEY user@host
  2. If you see Offering public key followed by Authentications that can continue, the key is sent but rejected. Go to the server-side fixes below.
  3. If you see identity file ... type -1 or no key is offered, the client is not using your key. Go to the next fix.

2.Make the client use the right key

Easy

A frequent cause is that the correct key is simply not being offered.

  1. Start the agent, add your key and list what is loaded.
    Terminal
    eval "$(ssh-agent -s)"
    ssh-add ~/.ssh/KEY
    ssh-add -l
  2. Or name the key explicitly with -i ~/.ssh/KEY, or add an IdentityFile line for the host in ~/.ssh/config.
  3. Check you are using the username your server or cloud image expects, not just root.

3.Tighten permissions on the client

Easy

ssh ignores a private key that other users can access.

  1. Restrict the folder and your private keys.
    Terminal
    chmod 700 ~/.ssh
    chmod 600 ~/.ssh/id_*
  2. Keep ~/.ssh/config private to your user as well.

4.Fix permissions and ownership on the server

ModerateChanges settings

With StrictModes on, sshd ignores keys in folders that are too open or owned by someone else.

Before you start: Run these as the affected user, from a console or another working admin session, so you do not lock yourself out. Replace user with the real account name.

  1. Set the recommended modes and ownership on the account's SSH files.
    Terminal
    chmod 700 ~/.ssh
    chmod 600 ~/.ssh/authorized_keys
    chown -R user:user ~/.ssh

5.Install the public key correctly

Moderate

The key may be missing from authorized_keys or broken across two lines.

  1. If you have another way in, copy the key with ssh-copy-id.
    Terminal
    ssh-copy-id -i ~/.ssh/KEY.pub user@host
  2. If password login is disabled, add the key through your cloud provider's console or tooling instead.
  3. Make sure the key sits on one single line in authorized_keys, and that AuthorizedKeysFile in the server config points at the file you edited.

6.Check the effective sshd configuration

AdvancedChanges settings

A setting may be rejecting your account or disabling key login. On many systems the main file pulls in extra files, so the value in /etc/ssh/sshd_config is not always the one in force.

Before you start: Keep your current session open while editing. A broken sshd_config can stop new logins.

  1. Print the values sshd actually uses. This is the reliable check, because it reflects every file sshd read.
    Terminalneeds sudo / root
    sudo sshd -T | grep -Ei 'pubkeyauthentication|passwordauthentication|allowusers|denyusers|authorizedkeysfile|strictmodes'
  2. Check whether /etc/ssh/sshd_config starts with an Include /etc/ssh/sshd_config.d/*.conf line, and look through that folder for drop-in files. sshd uses the first value it reads for a setting, so a drop-in can override what you set in the main file.
    Terminalneeds sudo / root
    head -n 20 /etc/ssh/sshd_config
    ls /etc/ssh/sshd_config.d/
    grep -ri 'PubkeyAuthentication\|PasswordAuthentication\|AllowUsers' /etc/ssh/sshd_config /etc/ssh/sshd_config.d/
  3. Fix the setting in the file that actually wins, then test the config for syntax errors and reload sshd.
    Terminalneeds sudo / root
    sudo sshd -t
    sudo systemctl reload sshd
  4. Re-run the sshd -T command to confirm the effective value changed. Also confirm the account is not locked and that its home directory is mounted and not encrypted at login time.

7.Old RSA/SHA-1 systems: temporary workaround

AdvancedChanges settings

OpenSSH 8.8 disabled ssh-rsa signatures by default, so very old clients or servers can fail against current ones.

Before you start: This re-enables a weak algorithm. Use it only as a stopgap to get in. The OpenSSH 8.8 notes recommend moving to Ed25519 or ECDSA keys or upgrading the old system.

  1. Add an entry for that host to ~/.ssh/config.
    Config
    Host old-host
        HostkeyAlgorithms +ssh-rsa
        PubkeyAcceptedAlgorithms +ssh-rsa
  2. Once connected, move to an Ed25519 or ECDSA key, install it, and remove the workaround.

Check that it worked

  • ssh user@host logs you in without the Permission denied message.
  • ssh -v user@host shows Authentication succeeded (publickey).

If it still fails

  • Compare the ssh -vvv output with the server's SSH log, since the server side often names the exact reason.
  • Ask whoever manages the server or cloud account to confirm the correct username, the key pair attached to the instance and any AllowUsers rules.
  • If the account genuinely uses Kerberos, you need a valid ticket from kinit first. This is rare.

Questions

Do I need Kerberos or GSSAPI to fix this?

Almost never. The gssapi entries are Kerberos methods the server lists. Unless your account really uses Kerberos, work on the public key side instead.

Sources

  1. sshd_config(5) manualOfficial · OpenBSD
  2. ssh(1) manualOfficial · OpenBSD
  3. OpenSSH 8.8 release notesOfficial · OpenSSH