Talk to the NOC, IST hours — +91 75994 50220 support@bigdomainhost.com
Guide

Fix "Permission denied (publickey)" when you SSH into a server

This error means SSH reached the server but the server refused every key your computer offered. The cause is almost always one of a short list: the wrong key, the wrong user, file permissions, or an sshd setting. This guide shows how to find which one in a couple of minutes, with exact commands for Ubuntu 24.04 and 22.04, Windows and GitHub.

Short answer: "Permission denied (publickey)" means the server accepts only key logins and rejected every key your client offered. Run ssh -v to see which key was sent, point ssh at the right key with -i, check the username, then on the server fix authorized_keys and its permissions (700 for .ssh, 600 for the file) and read the auth log.

What "Permission denied (publickey)" actually means

When you see user@host: Permission denied (publickey)., the network part of SSH worked. Your computer reached the server, the encrypted connection was set up and the server proved its identity. What failed is the next step: user authentication. The server told your client which login methods it accepts (the word in brackets), your client tried every key it had, and the server accepted none of them.

That narrows the problem to four places:

  • The client did not offer the right private key, or could not read it.
  • The username is wrong, so the server checks the wrong account's keys.
  • The server cannot find or will not trust the matching public key in authorized_keys, often because of file permissions.
  • The server's settings refuse this user or this key type, for example PermitRootLogin no or an old RSA key.

This is a different problem from "Connection refused" or "Connection timed out", which mean you never reached the SSH service at all. If you see one of those instead, use our SSH connection refused guide.

Step 1: run ssh -v and read the authentication lines

Guessing wastes time. The -v flag makes the client print what it is doing, and the ssh manual describes it as the tool for debugging connection, authentication and configuration problems. Run the same command that fails, with -v added:

ssh -v deploy@203.0.113.10

Ignore the first screen of output and look for these lines near the end:

debug1: Authentications that can continue: publickey
debug1: Offering public key: /home/you/.ssh/id_ed25519 ED25519 SHA256:...
debug1: Authentications that can continue: publickey
debug1: No more authentication methods to try.
deploy@203.0.113.10: Permission denied (publickey).

What they tell you:

  • No "Offering public key" line at all: your client has no key to offer. It is not in the default location, the agent is empty, or the file was ignored because of its permissions.
  • "Offering public key" for the wrong file: the client is sending a different key from the one installed on the server. Point it at the right one with -i.
  • "Offering public key" for the right file, then refused: the client side is fine. The server does not accept that key for that user, so the fix is on the server.
  • "Server accepts key" but still denied: the key matched, but the client could not use the private key, usually a wrong passphrase or an unreadable file.

Add more letters (-vv, -vvv) for more detail if needed. Remove your hostnames and IP addresses before you paste the output anywhere public.

Quick diagnosis table

Common "Permission denied (publickey)" variants and their usual cause
What you seeMost likely causeFirst thing to try
No "Offering public key" line in ssh -vKey not found, not loaded or ignoredls -l ~/.ssh, then ssh -i ~/.ssh/id_ed25519 ...
WARNING: UNPROTECTED PRIVATE KEY FILE!Private key readable by other users, so ssh ignores itchmod 600 ~/.ssh/id_ed25519
Key offered, then refusedPublic key missing from the server's authorized_keys, wrong user, or bad permissions on the serverCheck the username, then the server's auth log
Too many authentication failuresThe agent offered many keys and hit the server's attempt limit-o IdentitiesOnly=yes -i ~/.ssh/key
no mutual signature algorithm in -v outputOld ssh-rsa (SHA-1) signatures, disabled by default since OpenSSH 8.8Use an Ed25519 key
Works as root, fails as deploy (or the reverse)Key installed in the other account's authorized_keys, or PermitRootLogin / AllowUsers blocks the usersudo sshd -T | grep -i -E 'permitrootlogin|allowusers'
git@github.com: Permission denied (publickey)Key not added to your GitHub account, wrong user in the remote URL, or sudo gitssh -vT git@github.com
Permission denied (publickey,password)Password login is also allowed; the key failed and the password was wrong or skippedFix the key; do not rely on the password

Fixes on your computer (the client)

Check the key exists and use it explicitly

On Ubuntu, macOS or Git Bash on Windows, list your keys:

ls -l ~/.ssh

You should see a pair such as id_ed25519 (private) and id_ed25519.pub (public). By default ssh tries ~/.ssh/id_rsa, id_ecdsa, id_ecdsa_sk, id_ed25519 and a few others. If your key has another name, such as mumbai-vps or a .pem file a panel gave you, ssh will not find it on its own. Name it:

ssh -i ~/.ssh/mumbai-vps -o IdentitiesOnly=yes deploy@203.0.113.10

IdentitiesOnly=yes tells ssh to use only the keys you configured, even if the agent holds others. If you have no key at all, create one with ssh-keygen -t ed25519 and install the public half on the server, as our SSH keys guide shows.

Fix permissions on the private key

The ssh manual says private key files should be readable by you and not accessible by others, and that ssh will simply ignore a private key file if it is accessible by others. You will see a warning such as Permissions 0644 for '/home/you/.ssh/id_ed25519' are too open. Fix it with:

chmod 700 ~/.ssh
chmod 600 ~/.ssh/id_ed25519
chmod 644 ~/.ssh/id_ed25519.pub

On Windows, the same rule applies to keys in C:\Users\you\.ssh. If you copied a key from another drive or a shared folder, open the file's Properties, then Security, and remove access for every account except your own.

Save the host in ~/.ssh/config

Once a command works, stop retyping it. Add an entry to ~/.ssh/config:

Host mumbai-vps
    HostName 203.0.113.10
    User deploy
    IdentityFile ~/.ssh/mumbai-vps
    IdentitiesOnly yes

Now ssh mumbai-vps uses the right user and key every time, and so do scp, rsync and Git. The manual says this file must not be writable by others, so keep it at chmod 600.

"Too many authentication failures"

If ssh-add -l lists many keys, your client offers each one in turn. The server counts each as a failed attempt, and MaxAuthTries defaults to 6, so it may disconnect you before it reaches the right key. The IdentitiesOnly setting above fixes this.

Old RSA keys and "no mutual signature algorithm"

OpenSSH 8.8, released in September 2021, disabled RSA signatures that use the SHA-1 hash (the ssh-rsa algorithm) by default, because SHA-1 is broken. Ubuntu 22.04 ships OpenSSH 8.9 and Ubuntu 24.04 ships 9.6, so both have this default. For most users nothing changes, because RSA keys automatically use SHA-256 or SHA-512 signatures where the other side supports them. The problem appears when the other end is very old, such as an old appliance, router or a long-unpatched server. In the -v output you may see no mutual signature algorithm just before the key is skipped.

The lasting fix is a new key type: create an Ed25519 key and install it. The release notes show a stopgap for a single old host, which you should remove once the old side is upgraded:

Host old-host
    HostkeyAlgorithms +ssh-rsa
    PubkeyAcceptedAlgorithms +ssh-rsa

Fixes on the server

If the client offers the right key and the server still refuses it, you need a shell on the server to look. Use another working login, a password session if one is still allowed, or your provider's out-of-band console. Do not close an open session while you change SSH settings.

Read the server log first

The client is told only "denied". The server log says why. On Ubuntu 24.04 and 22.04 the service is called ssh:

sudo journalctl -u ssh -n 50 --no-pager
sudo tail -n 50 /var/log/auth.log

Try the login again from your computer and watch for new lines. Messages about "bad ownership or modes" point at permissions; a line saying the user is not allowed points at AllowUsers or PermitRootLogin; a line about a key type not being accepted points at PubkeyAcceptedAlgorithms.

Check the public key is really in authorized_keys

By default sshd reads .ssh/authorized_keys (and .ssh/authorized_keys2) in the home directory of the user you log in as. A key in /root/.ssh/authorized_keys does nothing for deploy, and the reverse. Compare the key on your computer with the file on the server:

# on your computer
cat ~/.ssh/id_ed25519.pub

# on the server, as the target user
cat ~/.ssh/authorized_keys

Each key must be one single line: type, long base64 string, optional comment. Common faults are a line broken in two by copy and paste, a private key pasted by mistake (it starts with -----BEGIN OPENSSH PRIVATE KEY-----), or Windows line endings from a text editor. To add a key correctly from a machine that can still log in with a password, use ssh-copy-id, which appends the key to the remote user's authorized_keys and creates the file and directory if needed:

ssh-copy-id -i ~/.ssh/id_ed25519.pub deploy@203.0.113.10

Fix ownership and permissions on the server

This is a very common server-side cause. sshd's StrictModes setting, which is on by default, checks the modes and ownership of the user's files and home directory before accepting a login. Typical triggers are a home directory set to 777, or a .ssh folder created with sudo so that root owns it. Fix it as root, replacing deploy with the real user:

sudo chown -R deploy:deploy /home/deploy/.ssh
sudo chmod go-w /home/deploy
sudo chmod 700 /home/deploy/.ssh
sudo chmod 600 /home/deploy/.ssh/authorized_keys

Do not turn off StrictModes to make the error go away. The manual explains it exists because people sometimes leave their directory or files world-writable by accident, which would let another user add their own key.

Check the effective sshd settings

sshd -T prints the configuration sshd will actually use, after every included file. That matters on Ubuntu, where /etc/ssh/sshd_config includes files from /etc/ssh/sshd_config.d/, and for each keyword the first value sshd reads wins. A cloud-init or hardening file there can override what you see in the main file.

sudo sshd -T | grep -i -E 'pubkeyauthentication|authorizedkeysfile|permitrootlogin|allowusers|allowgroups|pubkeyacceptedalgorithms'

Check that:

  • pubkeyauthentication yes (the default).
  • authorizedkeysfile still points at .ssh/authorized_keys, unless you moved keys on purpose.
  • permitrootlogin is not no if you are logging in as root. The default, prohibit-password, allows root with a key but not with a password.
  • If allowusers or allowgroups appears, your user is listed.

After any change, test the syntax and reload. Keep your current session open and test from a second terminal:

sudo sshd -t && sudo systemctl reload ssh

Windows Server as the SSH server

On Windows with the built-in OpenSSH Server, accounts in the Administrators group do not use the per-user authorized_keys file. Microsoft's key management guide puts their keys in C:\ProgramData\ssh\administrators_authorized_keys, with access limited to Administrators and SYSTEM, which its example sets with icacls:

icacls.exe "C:\ProgramData\ssh\administrators_authorized_keys" /inheritance:r /grant "Administrators:F" /grant "SYSTEM:F"

A key placed in C:\Users\Administrator\.ssh\authorized_keys for an admin account is a common reason key login fails on a Windows server. On a Windows install in another language, Microsoft's example uses the Administrators group's SID, *S-1-5-32-544, in place of the group name.

git@github.com: Permission denied (publickey)

The same error from Git means GitHub did not accept any key your computer offered. GitHub's troubleshooting page covers the causes; the main checks are:

  1. Test the connection directly. Run ssh -T git@github.com. A working key returns a greeting with your username. Use ssh -vT git@github.com to see which keys were offered.
  2. Always use the git user. The remote must be git@github.com:owner/repo.git, not your own username.
  3. Make sure a key is loaded. ssh-add -l -E sha256 lists the keys in your agent with fingerprints you can match against the SSH keys page in your GitHub settings.
  4. Do not use sudo git. GitHub notes that if you made your key without sudo and then run sudo git push, you are not using the key you generated, because root has its own ~/.ssh.

On a server that pulls code during deployment, the key must belong to the user that runs git, for example www-data or deploy, and be added to GitHub as a deploy key or to a machine account.

Common mistakes

  • Logging in as the wrong user. Many images expect root, ubuntu or a user you created. The key is tied to one account.
  • Creating .ssh with sudo. The folder ends up owned by root and StrictModes rejects it.
  • Pasting the private key on the server. Only the .pub line goes into authorized_keys. If you pasted a private key anywhere public, create a new key pair.
  • Turning password login back on as the fix. It hides the real fault and reopens the server to password guessing.
  • Editing only the main sshd_config. A file in sshd_config.d may override it. Check with sshd -T.
  • Reloading sshd with a broken config and closing your only session. Always run sshd -t first and keep a session or console open.

On a Bigdomainhost VPS

When you deploy a Bigdomainhost KVM VPS, you paste your SSH public key at order time and log in as root with that key once the server is ready; as our docs explain, this keeps password login off from the first boot. If you later get "Permission denied (publickey)", for example after adding a new user or replacing your laptop, open the out-of-band console in the control panel. It works without SSH, so you can fix authorized_keys or permissions from there and follow the server-side steps above. Every VPS comes with full root access, so nothing in this guide needs a support ticket.

If you are still stuck, send your ssh -v output, with IP addresses removed, to us on WhatsApp at any time, or call during IST working hours.

Bigdomainhost wrote this guide with AI assistance and sells the VPS servers it mentions. OpenSSH behaviour was checked against the OpenBSD manual pages and OpenSSH release notes on 28 November 2026; defaults can change between versions, so check man sshd_config on your own system.

Sources (checked )

Answers

Frequently asked questions

Still unsure? Call +91 75994 50220 or write to support@bigdomainhost.com — a human replies in IST hours.

What does Permission denied (publickey) mean?

It means you reached the SSH server, but the server only allows key-based login and did not accept any key your computer offered. The problem is the key, the username, file permissions on the server, or an sshd setting, not the network.

How do I find out which key SSH is sending?

Run your ssh command with -v added. Lines starting with "Offering public key" show each key the client tried. If no such line appears, your client has no usable key; if the right key is offered and refused, the fix is on the server.

Why does SSH ignore my private key?

The ssh client ignores a private key file that other users can access. Run chmod 600 on the key and chmod 700 on the ~/.ssh folder. You will usually also see a warning that the permissions are too open.

My key is in authorized_keys but SSH still says permission denied. Why?

Usually permissions or ownership. With StrictModes on, which is the default, sshd checks the ownership and modes of the home directory, .ssh folder and authorized_keys file and refuses the login if they are wrong, for example writable by others or owned by root. Also check the key is in the home directory of the user you log in as, on one line.

How do I fix git@github.com: Permission denied (publickey)?

Run ssh -vT git@github.com to see which key is offered, check the key is added to your GitHub account, make sure the remote uses the git user, and do not run git with sudo, because root uses a different set of keys.

What does "Too many authentication failures" mean?

Your SSH agent offered several keys and the server stopped at its limit, which is 6 attempts by default. Use -i with the right key and -o IdentitiesOnly=yes, or set IdentitiesOnly yes for that host in ~/.ssh/config.

Should I just turn password login back on?

No. It hides the real problem and lets attackers guess passwords again. Use your provider's console or another working session to fix the key, then keep password login off.

How do I get into my server if no key works?

Use the out-of-band console in your hosting control panel. It works like a keyboard and screen attached to the server and does not depend on SSH, so you can fix authorized_keys and permissions from there.

Support that picks up the phone.

In IST hours, in Hindi or English, and WhatsApp replies fastest at any time. Sales, migration and emergencies all reach the same engineers. No offshore queue, no 48-hour first reply.

Need cPanel or WHM with the ports already sorted?

Web & cPanel hosting comes with cPanel ready to log in to, reseller hosting adds white-label WHM, and a KVM VPS can have cPanel & WHM pre-installed. Call +91 75994 50220 or email support@bigdomainhost.com.