Submitting the form below will ensure a prompt response from us.
When connecting to a remote server using SSH, you might encounter the error:
Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
This error indicates that the SSH client attempted authentication but the server rejected it. It usually occurs when the server expects public key authentication, but the client either does not provide a valid key or the key is not configured correctly.
Understanding why the permission denied (publickey,gssapi-keyex,gssapi-with-mic) error occurs can help you quickly restore secure server access.
The message:
Permission denied (publickey,gssapi-keyex,gssapi-with-mic)
means the SSH server tried several authentication methods but none succeeded.
The authentication methods shown include:
Most commonly, the failure occurs with public key authentication.
If you try to connect without a valid SSH key, authentication fails.
Example command:
ssh user@server-ip
If no key is available or loaded, the server rejects the connection.
SSH requires strict file permissions for security.
Incorrect permissions may cause authentication failure.
Example fix:
chmod 600 ~/.ssh/id_rsa
chmod 700 ~/.ssh
Even if the private key exists locally, the corresponding public key must be stored on the server.
Location on server:
~/.ssh/authorized_keys
Add your public key:
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
SSH authentication depends on the correct user account.
Example connection:
ssh ubuntu@server-ip
Using the wrong username may trigger the permission denied (publickey,gssapi-keyex,gssapi-with-mic) error.
If your SSH key is not loaded into the SSH agent, authentication may fail.
Start the agent:
eval "$(ssh-agent -s)"
Add your key:
ssh-add ~/.ssh/id_rsa
ssh-keygen -t rsa -b 4096
This generates:
Use:
ssh-copy-id user@server-ip
This automatically adds the key to authorized_keys.
On the server:
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
Incorrect permissions can cause authentication failures.
Try connecting again:
ssh -i ~/.ssh/id_rsa user@server-ip
Use verbose SSH output to identify the problem.
ssh -v user@server-ip
For more detailed logs:
ssh -vvv user@server-ip
This command shows which authentication method fails.
Developers sometimes test SSH connections programmatically using Python.
Example using paramiko:
import paramiko
host = "server-ip"
username = "user"
key_file = "/home/user/.ssh/id_rsa"
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
try:
client.connect(hostname=host, username=username, key_filename=key_file)
print("SSH connection successful")
except Exception as e:
print("Connection failed:", e)
client.close()
This script helps validate SSH authentication automatically.
To avoid the permission denied (publickey,gssapi-keyex,gssapi-with-mic) error:
Proper SSH configuration improves both security and reliability.
The permission denied (publickey,gssapi-keyex,gssapi-with-mic) error often appears in these situations:
Understanding these scenarios helps troubleshoot quickly.
Need Help Fixing SSH Errors?
Our DevOps experts resolve server authentication and SSH configuration issues.
The error permission denied (publickey,gssapi-keyex,gssapi-with-mic) occurs when the SSH server cannot authenticate the client using the available methods.
The most common causes include:
By generating keys, adding them to the server, fixing permissions, and verifying SSH configuration, you can quickly resolve the issue and restore secure remote access.