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.
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 -vshows 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-ifile, key not loaded in the agent, orssh-add -lshowing 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
StrictModesis on by default. sshd then refuses keys when the home directory,~/.sshorauthorized_keysis 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
AuthorizedKeysFilemay 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
AllowUsersorDenyUsersexcludes the account,PubkeyAuthentication nois 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
It shows whether your key is even being sent, which tells you whether to look at the client or the server.
- Connect with maximum verbosity, using your real key path, user and host.
ssh -vvv -i ~/.ssh/KEY user@host - If you see
Offering public keyfollowed byAuthentications that can continue, the key is sent but rejected. Go to the server-side fixes below. - If you see
identity file ... type -1or no key is offered, the client is not using your key. Go to the next fix.
2.Make the client use the right key
A frequent cause is that the correct key is simply not being offered.
- Start the agent, add your key and list what is loaded.
eval "$(ssh-agent -s)" ssh-add ~/.ssh/KEY ssh-add -l - Or name the key explicitly with
-i ~/.ssh/KEY, or add anIdentityFileline for the host in~/.ssh/config. - Check you are using the username your server or cloud image expects, not just
root.
3.Tighten permissions on the client
ssh ignores a private key that other users can access.
- Restrict the folder and your private keys.
chmod 700 ~/.ssh chmod 600 ~/.ssh/id_* - Keep
~/.ssh/configprivate to your user as well.
4.Fix permissions and ownership on the server
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.
- Set the recommended modes and ownership on the account's SSH files.
chmod 700 ~/.ssh chmod 600 ~/.ssh/authorized_keys chown -R user:user ~/.ssh
5.Install the public key correctly
The key may be missing from authorized_keys or broken across two lines.
- If you have another way in, copy the key with
ssh-copy-id.ssh-copy-id -i ~/.ssh/KEY.pub user@host - If password login is disabled, add the key through your cloud provider's console or tooling instead.
- Make sure the key sits on one single line in
authorized_keys, and thatAuthorizedKeysFilein the server config points at the file you edited.
6.Check the effective sshd configuration
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.
- Print the values sshd actually uses. This is the reliable check, because it reflects every file sshd read.
sudo sshd -T | grep -Ei 'pubkeyauthentication|passwordauthentication|allowusers|denyusers|authorizedkeysfile|strictmodes' - Check whether
/etc/ssh/sshd_configstarts with anInclude /etc/ssh/sshd_config.d/*.confline, 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.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/ - Fix the setting in the file that actually wins, then test the config for syntax errors and reload sshd.
sudo sshd -t sudo systemctl reload sshd - Re-run the
sshd -Tcommand 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
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.
- Add an entry for that host to
~/.ssh/config.Host old-host HostkeyAlgorithms +ssh-rsa PubkeyAcceptedAlgorithms +ssh-rsa - Once connected, move to an Ed25519 or ECDSA key, install it, and remove the workaround.
Check that it worked
ssh user@hostlogs you in without the Permission denied message.ssh -v user@hostshowsAuthentication succeeded (publickey).
If it still fails
- Compare the
ssh -vvvoutput 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
AllowUsersrules. - If the account genuinely uses Kerberos, you need a valid ticket from
kinitfirst. 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
- sshd_config(5) manualOfficial · OpenBSD
- ssh(1) manualOfficial · OpenBSD
- OpenSSH 8.8 release notesOfficial · OpenSSH