Permission denied (publickey) means the OpenSSH server only allows key authentication and rejected every key your client offered for that user. Four causes cover almost every case: the wrong remote user, a key that is not loaded or offered, bad permissions on ~/.ssh or authorized_keys, and a key signature algorithm the other side refuses.
What Permission denied (publickey) tells you about the OpenSSH server
OpenSSH prints this message when the publickey method has failed and no other authentication method is left. The text in parentheses lists the methods the server accepts. If it only says publickey, password login is disabled and there is no fallback. sshd never tells the client why a key was refused, by design. You diagnose from both ends: verbose client output and the server log.
Step 1: read ssh -vvv output to see which SSH key is offered
The -v flag raises ssh verbosity, up to three levels. -vvv shows every key the client tries and how the server answers. Filtering saves you from scrolling through hundreds of lines:
ssh -vvv -p 22 [email protected] 2>&1 | grep -E 'Connecting to|Offering|Trying|Authentications|Server accepts|No more'These are the lines that matter:
- Connecting to: the real host and port after ~/.ssh/config is applied. The default is TCP port 22.
- Offering public key: the key being sent. If none appears, the client cannot find a key (step 3).
- Authentications that can continue: publickey right after an offer: the server rejected that key.
- Server accepts key: the key is valid. A failure after this points to the passphrase or the agent.
- No more authentication methods to try: the client has run out of keys.
Step 2: confirm the remote user of the SSH connection
If you do not specify a user, ssh sends your local username. On a phone or a borrowed machine, that name rarely matches the server account. ssh -G prints the effective configuration without connecting:
ssh -G server.example.com | grep -E '^(user|hostname|port|identityfile) 'Every account has its own authorized_keys. A key authorised in /home/ana/.ssh/authorized_keys will not let you in as root or as any other user. Cloud images usually create their own non-root user, so check your provider's documentation before digging further.
Step 3: check the SSH key is loaded in the agent and actually offered
ssh-add -l lists the keys held by the agent. If it reports no identities, the client only tries the default files in ~/.ssh. To force one specific key and compare fingerprints:
ssh-add -l
ssh-add ~/.ssh/id_ed25519
ssh -i ~/.ssh/id_ed25519 -o IdentitiesOnly=yes [email protected]
ssh-keygen -lf ~/.ssh/id_ed25519.pub
# on the server:
ssh-keygen -lf ~/.ssh/authorized_keysIdentitiesOnly=yes stops the agent from offering a pile of keys before the right one. sshd drops the connection once it reaches its MaxAuthTries limit. If your public key's SHA256 fingerprint is not listed for authorized_keys, you copied a different key.
In termi1, you can generate keys on the phone itself, and they are stored in the system's secure storage. The private key never leaves the device, so what you paste on the server is always the public half. On a Mac, termi1 Companion installs that public key when you pair using a six-digit code.
Step 4: fix ~/.ssh and authorized_keys permissions on the server
OpenSSH expects ~/.ssh at mode 700, and authorized_keys and private keys at 600. With StrictModes on, which is the default, sshd ignores authorized_keys if the file, ~/.ssh or the home directory is writable by other users.
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
chown -R ana:ana ~/.ssh
chmod go-w ~
ls -ld ~ ~/.ssh ~/.ssh/authorized_keysThe same rule applies on the client. If a private key is readable by others, ssh prints UNPROTECTED PRIVATE KEY FILE and refuses to use it. Ask termi1's AI to “fix my .ssh permissions” and the command is typed at the prompt without pressing Enter. On connections tagged as production, Production Guard holds back any change before it reaches the prompt.
Step 5: read /var/log/auth.log to see why sshd refuses the key
On Debian and Ubuntu, sshd logs authentication attempts to /var/log/auth.log. On journald-only systems, the same information is available through journalctl:
sudo tail -f /var/log/auth.log
sudo journalctl -u ssh -f # Debian/Ubuntu
sudo journalctl -u sshd -f # RHEL, Fedora, Arch
sudo sshd -T | grep -iE 'pubkey|authorizedkeys|strictmodes'- Invalid user: the account does not exist on the server (step 2).
- Authentication refused: bad ownership or modes: wrong permissions or owner (step 4).
- Connection closed by authenticating user … [preauth]: a key was offered but matched nothing in authorized_keys.
- Messages mentioning ssh-rsa and PubkeyAcceptedAlgorithms: the signature algorithm was refused (step 6).
If the log says nothing useful, set LogLevel VERBOSE in sshd_config to record the fingerprint of every key tried. See the documented sshd_config server options. On termi1's keyboard, Ctrl+C stops the tail -f, and tmux keeps the session alive if your network changes.
Step 6: rule out OpenSSH refusing the key's ssh-rsa signature
Since OpenSSH 8.8 (September 2021), the SHA-1 based ssh-rsa signature has been disabled by default. An RSA key can fail even when it was copied correctly, if one side only negotiates that signature. The cleanest fix is Ed25519, which OpenSSH has supported since version 6.5 (January 2014):
ssh-keygen -t ed25519 -C "ana@phone"
ssh-copy-id -i ~/.ssh/id_ed25519.pub [email protected]ssh-copy-id needs another working way in. Without one, append the public key line to authorized_keys from your provider's console. Client flags are listed in the official ssh client manual.
Diagnosing Permission denied (publickey) on mobile versus desktop
| Check | Desktop with OpenSSH | Mobile (iOS/Android) |
|---|---|---|
| Negotiation detail | ssh -vvv in a local terminal | Depends on the client; the server log is the reference |
| Remote user | ssh -G shows the effective value | User field of the saved connection |
| Key offered | ssh-add -l and ssh -i | Key assigned to the connection; in termi1, kept in secure storage |
| Server permissions | chmod from the session | chmod from the session, with Ctrl and Tab on termi1's keyboard |
| Inspect authorized_keys | cat or a remote editor | cat or termi1's built-in SFTP |
If you manage servers from your pocket, the SSH terminal for iOS and Android works without an account.
Frequently asked questions
Why does SSH say Permission denied (publickey) when my key is in authorized_keys?
SSH reports Permission denied (publickey) even with the key in authorized_keys when sshd ignores that file or it belongs to a different user. Typical causes are open permissions with StrictModes enabled, the wrong owner, logging in as another account, or a refused ssh-rsa signature.
What permissions does the .ssh folder need?
The .ssh folder needs mode 700, so only its owner can read, write and enter it. The authorized_keys file and private keys need mode 600. The home directory must not be writable by the group or by other users, otherwise sshd refuses the key.
Where is the SSH log on Ubuntu?
The SSH log on Ubuntu is /var/log/auth.log, and you can follow it live with sudo tail -f /var/log/auth.log. The same events are available in journald through sudo journalctl -u ssh -f. Setting LogLevel VERBOSE in sshd_config records the fingerprint of every key tried.
Can Mosh get around Permission denied (publickey)?
Mosh cannot get around Permission denied (publickey), because it starts mosh-server over an initial SSH connection. If key authentication fails there, Mosh never opens its UDP session. Fix SSH access first; after that, Mosh keeps the session alive when you switch networks.