> ## Documentation Index
> Fetch the complete documentation index at: https://help.freakhosting.com/llms.txt
> Use this file to discover all available pages before exploring further.

# How to Fix "Permission denied (publickey)" in SSH

> Fix "Permission denied (publickey)" in SSH: use the right username and key with ssh -i, add the key to authorized_keys and fix .ssh permissions.

"Permission denied (publickey)" means SSH is running and reachable, but the server only accepts key logins and didn't accept your key. Usually you used the wrong username, your SSH client offered a different key, the public key isn't in `~/.ssh/authorized_keys`, or that folder has the wrong permissions. Run `ssh -v` to see which key is offered, then fix the server side from the VNC console.

```text theme={null}
alex@203.0.113.10: Permission denied (publickey).
```

| Difficulty | Time | Works on | Needs |
| - | - | - | - |
| Beginner | 5 to 15 minutes | Ubuntu 22.04 / 24.04, Debian 12 / 13, AlmaLinux and Rocky Linux 9 / 10 | Your private key, console access for server-side fixes |

## Before you start

* The text in brackets lists the login methods the server still offers. `(publickey)` alone means password logins are switched off, so typing a password can't work.
* For fixes on the server, use the [VNC console](https://help.freakhosting.com/portals/vps-panel/how-to-enable-and-use-vnc-console-access.md) on a VPS. If you also forgot the password, [reset the root password](https://help.freakhosting.com/portals/vps-panel/how-to-reset-your-vps-root-password.md) first. On a dedicated server, [open a ticket](https://freakhosting.com/clientarea/submitticket.php) for KVM/IPMI access.
* Commands use `sudo`. As root, leave it out.

## Step 1: See what your client sends

```bash theme={null}
ssh -v alex@203.0.113.10
```

Look for these lines:

```text theme={null}
debug1: Authentications that can continue: publickey
debug1: Offering public key: /home/you/.ssh/id_ed25519 ED25519 SHA256:fE6myjOU...
```

* No `Offering public key` line: your client has no key to offer. Point to it with `-i` (Cause 2).
* A key is offered but no `Server accepts key` follows: the server doesn't know that key, or ignores it (Causes 2 to 4).

## Cause 1: Wrong username

The key is installed for one user only. Logging in as `root` when the key belongs to `alex`, or the reverse, fails.

**Fix:** use the user the key was set up for:

```bash theme={null}
ssh alex@203.0.113.10
ssh root@203.0.113.10
```

If `root` is refused but other users work, check `PermitRootLogin` in `/etc/ssh/sshd_config` and the files in `/etc/ssh/sshd_config.d/`. The value `no` blocks root completely. See [disable root login](https://help.freakhosting.com/portals/other/how-to-disable-root-login-over-ssh.md).

## Cause 2: Your client offers the wrong key

SSH tries your default keys (such as `~/.ssh/id_ed25519`). A key saved elsewhere, or with another name, isn't used automatically.

**Fix:** name the key:

```bash theme={null}
ssh -i ~/.ssh/myserver_ed25519 alex@203.0.113.10
```

Save it in your [SSH config file](https://help.freakhosting.com/portals/other/how-to-use-ssh-config-file-shortcuts.md) with `IdentityFile` so you don't have to type it. In PuTTY, select the `.ppk` file under **Connection > SSH > Auth > Credentials**. PuTTY can't use an OpenSSH key directly: convert it with PuTTYgen first.

## Cause 3: The public key isn't in authorized\_keys

**Check** on the console (replace `alex` with your user):

```bash theme={null}
sudo cat /home/alex/.ssh/authorized_keys
```

Compare it with the public key on your computer (`cat ~/.ssh/id_ed25519.pub`). The whole line must match, on one line.

**Fix:** add the public key, one key per line:

```bash theme={null}
sudo mkdir -p /home/alex/.ssh
echo 'ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAA... you@example.com' | sudo tee -a /home/alex/.ssh/authorized_keys
```

For `root`, the file is `/root/.ssh/authorized_keys`. To manage keys through the panel instead, see [manage SSH keys](https://help.freakhosting.com/portals/vps-panel/how-to-manage-ssh-keys.md).

## Cause 4: Wrong ownership or permissions

OpenSSH ignores `authorized_keys` if other users could change it. The SSH log shows:

```text theme={null}
Authentication refused: bad ownership or modes for directory /home/alex/.ssh
```

**Check** the log:

> [tab] Ubuntu / Debian
>
> ```bash theme={null}
> sudo journalctl -u ssh -n 30
> ```

> [tab] AlmaLinux / Rocky
>
> ```bash theme={null}
> sudo journalctl -u sshd -n 30
> ```

**Fix:** give the folder and file to the user and remove write access for others:

```bash theme={null}
sudo chown -R alex:alex /home/alex/.ssh
sudo chmod 700 /home/alex/.ssh
sudo chmod 600 /home/alex/.ssh/authorized_keys
sudo chmod go-w /home/alex
```

On AlmaLinux and Rocky, also restore the SELinux labels, which can be wrong on files copied in from elsewhere:

```bash theme={null}
sudo restorecon -Rv /home/alex/.ssh
```

## Cause 5: You wanted to log in with a password

If you don't have a key at all, the server needs password logins. Don't switch them on permanently on a public server. Instead, log in on the console, [create a key pair](https://help.freakhosting.com/portals/other/how-to-create-and-use-ssh-keys.md) on your computer and add the public key as in Cause 3.

## How to check it worked

```bash theme={null}
ssh -v alex@203.0.113.10
```

```text theme={null}
debug1: Server accepts key: /home/you/.ssh/id_ed25519 ED25519 SHA256:fE6myjOU...
Authenticated to 203.0.113.10 ([203.0.113.10]:22) using "publickey".
```

## Frequently asked questions

### Can I just copy my private key to the server?

No. Only the **public** key (the `.pub` file) goes on the server. The private key stays on your computer.

### It worked yesterday. What changed?

Common causes are a rebuild (which replaces `authorized_keys`), a new computer without your old key, or a `chmod -R 777` on the home folder. Check the log in Cause 4 first.

### Why does `ssh-copy-id` fail with the same error?

`ssh-copy-id` needs a working login to copy the key, usually a password. With password logins off, add the key through the console instead.

## Related guides

> [card] [VPS and dedicated server guides](https://help.freakhosting.com/portals/other/vps-and-dedicated-server-guides.md)
>
> Every guide in this section.

> [card] [Create and use SSH keys](https://help.freakhosting.com/portals/other/how-to-create-and-use-ssh-keys.md)
>
> Make a key pair and install it.

> [card] [Use PuTTY](https://help.freakhosting.com/portals/other/how-to-use-putty-to-connect-to-your-server.md)
>
> Keys and settings in PuTTY.

> [card] [SSH connection refused](https://help.freakhosting.com/portals/other/how-to-fix-ssh-connection-refused.md)
>
> When SSH doesn't answer on the port.

> [card] [Host key verification failed](https://help.freakhosting.com/portals/other/how-to-fix-host-key-verification-failed.md)
>
> The other common SSH warning.

***

> [!NOTE]
>
> **Checked against the official [OpenSSH sshd manual](https://man.openbsd.org/sshd) (AUTHORIZED\_KEYS FILE FORMAT) and [Ubuntu's OpenSSH server guide](https://ubuntu.com/server/docs/how-to/security/openssh-server/)** on 4 November 2026; the error, the `ssh -v` output, the wrong-key case and the "bad ownership or modes" log line were reproduced and fixed on Ubuntu 24.04 LTS (OpenSSH 9.6). The SELinux step was not tested.

> [!NOTE]
>
> ### Need Extra Help?
>
> If you encounter any issues, our support team is ready to assist:
>
> * **Live Chat:** Quick assistance via our website.
> * **Support Ticket:** [Open a Ticket](https://freakhosting.com/clientarea/submitticket.php)
> * **Discord:** [Join our Community](https://discord.gg/freakhosting)
> * **Email:** [support@freakhosting.com](mailto:support@freakhosting.com)

> [!TIP]
>
> ### Save on Your Hosting
>
> Ready to upgrade your hosting? Use code **KB20** at checkout for **20% off** your first order!

***

**Last Updated:** November 2026


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.