Error Encyclopedia

SSH Permission Denied (publickey) Error

Fix 'Permission denied (publickey)' SSH errors when connecting to GitHub, AWS, or remote servers.

What Does This Error Mean?

The 'Permission denied (publickey)' error means the SSH server rejected your connection because your public key is not recognized or the corresponding private key is not available to the SSH client.

Common Causes

1

SSH key has not been added to the remote server's authorized_keys

2

Wrong SSH key is being used (default key is not the right one)

3

Private key has incorrect permissions (too permissive)

4

ssh-agent is not running or the key is not added to it

5

Connecting with the wrong username

6

SSH key was removed from the server (e.g., GitHub deploy key removed)

How to Fix It

Check key permissions

SSH private keys must have strict permissions to be accepted.

# Fix private key permissions (Linux/macOS)
chmod 600 ~/.ssh/id_rsa
chmod 700 ~/.ssh
chmod 644 ~/.ssh/id_rsa.pub

# On Windows, check Properties → Security → Advanced
# The key should be readable only by the user

Add key to ssh-agent

Register your SSH key with the SSH agent.

# Start ssh-agent
ssh-agent bash
# or
eval "$(ssh-agent -s)"

# Add your key
ssh-add ~/.ssh/id_rsa

# List added keys
ssh-add -l

# Test connection
ssh -T git@github.com

Add public key to the remote server

Copy your public key to the server's authorized_keys.

# Copy public key to server
ssh-copy-id user@server.com

# Or manually append to ~/.ssh/authorized_keys
cat ~/.ssh/id_rsa.pub | ssh user@server.com "cat >> ~/.ssh/authorized_keys"

# For GitHub: add key at https://github.com/settings/keys
# Test: ssh -T git@github.com
# Should say: "Hi username! You've successfully authenticated"

Specify which key to use

Use -i flag to specify a specific private key.

# Connect with specific key
ssh -i ~/.ssh/my-custom-key user@server.com

# Or configure in ~/.ssh/config
Host myserver
  HostName server.com
  User ubuntu
  IdentityFile ~/.ssh/my-custom-key

Related Tools

Use these tools to debug and fix this error:

Related Errors

Other common errors in this category: