PuTTY "Server refused our key": why and how to fix it
PuTTY offered your public key and the server said no before any passphrase prompt. Usual causes: key not in authorized_keys, file modes, wrong user, ssh-rsa.
Server refused our key
PuTTY prints this when it offered a public key and the server would not accept it for that account. In SSH, a client may first ask "would you accept this key?" without signing anything (RFC 4252, section 7). PuTTY does that, and asks for your key's passphrase only after the server says yes. So when you see this line, the passphrase was never the problem, and PuTTY moves on to the next method, for example a password prompt, or, if the server allows only keys, PuTTY "No supported authentication methods available (server sent: publickey)".
For keys held in Pageant, the same refusal appears only in the Event Log (system menu, then Event Log), not in the window.
The PuTTY manual says this is almost certainly not a problem with PuTTY, and advises checking the server's configuration first.
Causes on the server
- The public key is not in that account's
authorized_keys. The server checks~/.ssh/authorized_keysof the user you log in as. Check the user name in thelogin as:prompt or under Connection, Data. - The key was pasted in the wrong format. OpenSSH wants each key on one line, starting with the key type, for example
ssh-ed25519 AAAA.... Copy it from PuTTYgen's "Public key for pasting into OpenSSH authorized_keys file" box. The file from PuTTYgen's Save public key button is in the RFC 4716 format (it starts with---- BEGIN SSH2 PUBLIC KEY ----and spans several lines), which OpenSSH does not read inauthorized_keys. On the server,ssh-keygen -i -f key.pubprints such a file as one OpenSSH line. A line broken in two by the editor fails the same way. - File permissions or ownership. With
StrictModeson (the default), the server ignoresauthorized_keysif it, the.sshfolder or the home folder is writable by group or others, or owned by someone else. The PuTTY manual suggestschmod go-w $HOME $HOME/.ssh $HOME/.ssh/authorized_keys. Details are in Authorized keys and permissions. - The key type is not accepted. OpenSSH 8.8 and later refuse RSA signatures made with SHA-1 (
ssh-rsa) by default. An older PuTTY that signs RSA keys only that way is refused. Update PuTTY, or use an Ed25519 key. See SSH "sign_and_send_pubkey: no mutual signature supported" for the same problem from the OpenSSH side. - The server looks somewhere else for keys.
AuthorizedKeysFileorAuthorizedKeysCommandinsshd_configcan point to another file or a directory service, and afrom=option on the key line limits where it may be used from.
Read the server log
If you can get in another way, the server's log can say why. On systemd hosts, journalctl -u ssh or journalctl -u sshd shows it. Two lines OpenSSH writes at its default log level (some versions add [preauth] at the end):
Authentication refused: bad ownership or modes for directory /home/user1/.ssh
userauth_pubkey: signature algorithm ssh-rsa not in PubkeyAcceptedAlgorithms
The first means fix the modes. The second means the RSA signature type is the problem.
Causes on your side
- The wrong key. The session's key file, or the first keys in Pageant, are not the one the server knows. With many keys in Pageant you can also hit the server's limit on attempts; see SSH "Too many authentication failures". Setting the right key file makes PuTTY use only that key from Pageant.
- The key file is not a PuTTY key. If the window shows "Unable to use key file" or "Unable to load key file" before this line, PuTTY could not read the file and offered nothing from it. Convert it in PuTTYgen; see Convert a PuTTY .ppk key to OpenSSH format, and PPK version 3.
Related
- PuTTY "No supported authentication methods available (server sent: publickey)"
- Authorized keys and permissions
- SSH "sign_and_send_pubkey: no mutual signature supported"
- SSH "Too many authentication failures"
- Key types and formats
- SSH error messages, what each one means
- Windows OpenSSH server asks for a password for an admin user: administrators_authorized_keys
Sources
- PuTTY manual, section 10.9: Server refused our key
- PuTTY manual, section 8.2.11 and 8.2.12: saving the public key, and the one-line OpenSSH format
- PuTTY manual, section 8.3: getting ready for public key authentication
- PuTTY manual, section 10.6: too many authentication failures and Pageant
- RFC 4252, section 7: public key method and SSH_MSG_USERAUTH_PK_OK
- sshd(8): AUTHORIZED_KEYS FILE FORMAT and the from= option
- ssh-keygen(1): -i to import an RFC 4716 public key
- sshd_config(5): StrictModes, AuthorizedKeysFile, AuthorizedKeysCommand, PubkeyAcceptedAlgorithms
- OpenSSH 8.8 release notes: RSA/SHA-1 signatures disabled by default
- OpenSSH portable source, auth2-pubkeyfile.c and auth2-pubkey.c: the log lines above