Fix ‘Permission denied (publickey)’ From OpenSSH RSA/SHA-1 Deprecation

Last Verified On: Kernel 6.8 / 6.12 LTS / Ubuntu 24.04 LTS & Debian 12/13 Moderate (Service Restart) Exit Code: 255

Direct Answer / TL;DR

OpenSSH 8.8+ on Ubuntu 24.04, Debian 12, and RHEL 9 disables the legacy ssh-rsa (RSA/SHA-1) signature algorithm, so legacy RSA key exchanges fail with 'Permission denied (publickey)'. The same RSA key works over rsa-sha2-256/512: re-enable ssh-rsa via PubkeyAcceptedAlgorithms on the lagging side, or migrate to ed25519 keys.

ssh -vvv -o PubkeyAcceptedAlgorithms=+ssh-rsa user@host
user@host: Permission denied (publickey).

Symptom & Exact Error Signature

Public-key authentication with RSA keys fails after one peer reaches OpenSSH 8.8/9.x+: the handshake and key exchange complete, then userauth fails and ssh(1) exits 255. The authoritative evidence is the sshd preauth log line naming the rejected signature algorithm.

$ ssh -vvv admin@build01
debug1: Offering public key: /home/admin/.ssh/id_rsa RSA SHA256:9S1G0w8kT8G1xqH3 explicit
debug3: receive packet: type 51
debug1: Authentications that can continue: publickey
admin@build01: Permission denied (publickey).

# Server logs: Ubuntu/Debian journalctl -u ssh | RHEL journalctl -u sshd | Alpine /var/log/messages
sshd[1842]: userauth_pubkey: signature algorithm ssh-rsa not in PubkeyAcceptedAlgorithms [preauth]
# Reverse case: a hardened client (>=8.8) facing a SHA-2-incapable peer never offers
# the RSA key at all; userauth cycles and the same client message ends with exit 255.

Root Cause Breakdown

ssh-rsa carries two meanings: the identifier of an RSA public-key blob in authorized_keys, and the legacy RSA-over-SHA-1 signature scheme defined by RFC 4253. Since SHA-1 collision attacks (2017), correct deployments negotiate via RFC 8332 — rsa-sha2-256 and rsa-sha2-512 — which OpenSSH has supported on both sides since 7.2 (2016).

OpenSSH 8.8.0 (2021-09) removed ssh-rsa from the compiled-in defaults of PubkeyAcceptedAlgorithms and HostKeyAlgorithms, and every 9.x/10.x release keeps that default. Ubuntu 24.04 (OpenSSH 9.6p1), Debian 12 (9.2p1), Arch (10.x) and Alpine enforce it upstream. RHEL/Alma/Rocky 9 additionally refuses SHA-1 signatures system-wide via update-crypto-policies (sshd backend /etc/crypto-policies/back-ends/opensshserver.config), independent of the packaged OpenSSH version.

The failure therefore means exactly one endpoint still signs RSA with SHA-1: an old client hitting a hardened server (see the userauth_pubkey rejection above), or a modern client against a peer with no SHA-2 support — OpenSSH <7.2, dropbear <2020.79, closed appliances, or an sshd with a restrictive algorithm list. Where both sides are hardened, RSA keys keep working automatically over rsa-sha2: a bare ssh-rsa AAAA... line in authorized_keys is not invalidated, only the signature hash changes. This is pure userspace negotiation in the SSH userauth layer after KEX; there is no kernel, PAM, or POSIX-signal component. Separately, OpenSSH 9.8 removed DSA at compile time by default (fully dropped in 10.x), so ssh-dss keys fail regardless of any configuration flags.

Step-by-Step Diagnostic & Fix Sequence

  1. Verify the state: dump offered and enforced algorithms, and let sshd name the failing peer.
    $ ssh -Q sig | grep -E '^(ssh-rsa|rsa-sha2)'      # both should print on 9.x clients
    ssh-rsa
    rsa-sha2-256
    rsa-sha2-512
    $ ssh-keygen -lf ~/.ssh/id_rsa.pub
    4096 SHA256:9S1G0w8kT8G1xqH3C admin@build01 (RSA)
    $ sudo sshd -T | grep -i pubkeyacceptedalgorithms # server effective list (first value wins)
    pubkeyacceptedalgorithms rsa-sha2-512,rsa-sha2-256,ecdsa-sha2-nistp256,ssh-ed25519,...
    $ ssh -G admin@build01 | grep -i pubkeyacceptedalgorithms  # client-side effective list
    $ sudo journalctl -u ssh -S -1h | grep userauth_pubkey
    sshd[1842]: userauth_pubkey: signature algorithm ssh-rsa not in PubkeyAcceptedAlgorithms [preauth]

    Interpretation: that log line means the server is the hardened side — upgrade the lagging client, or use Step 2b temporarily. A verbose client that never offers the RSA key at all means the peer lacks SHA-2 support (Step 2a). If the client offers the key, the server logs repeated Failed publickey ... RSA SHA256:... with no algorithm complaint, and the server also prints Authentication refused: bad ownership or modes, the problem is ~/.ssh/authorized_keys permissions, not algorithms.

  2. Apply the fix: remediate in the direction of the mismatch, then retire SHA-1 permanently.
    # 2a. Modern client -> SHA-2-incapable peer: allow the legacy fallback per-host only
    $ printf 'Host legacy-nasn    HostName 192.168.4.20n    PubkeyAcceptedAlgorithms +ssh-rsan' >> ~/.ssh/config
    $ chmod 600 ~/.ssh/config
    $ ssh -o PubkeyAcceptedAlgorithms=+ssh-rsa admin@build01   # one-shot equivalent, no persistent change
    
    # 2b. Pre-8.8 client -> hardened server: temporary server-side opt-out (drop-in, not global edit)
    $ printf 'PubkeyAcceptedAlgorithms +ssh-rsan' | sudo tee /etc/ssh/sshd_config.d/90-legacy-sha1.conf
    $ sudo sshd -t && sudo systemctl reload ssh        # RHEL/Arch/Alpine unit name: sshd
    $ sudo sshd -T | grep -i pubkeyacceptedalgorithms  # ssh-rsa now appended
    
    # 2c. Permanent: end the SHA-1 era with an Ed25519 key
    $ ssh-keygen -t ed25519 -a 100 -f ~/.ssh/id_ed25519 -C admin@build01
    $ ssh-copy-id -i ~/.ssh/id_ed25519.pub admin@build01
    $ ssh -i ~/.ssh/id_ed25519 -o IdentitiesOnly=yes -o BatchMode=yes admin@build01 'echo OK'
    # Optional hardening for the RSA private key format (bcrypt KDF): back up first
    $ cp -a ~/.ssh/id_rsa ~/.ssh/id_rsa.bak && ssh-keygen -o -p -f ~/.ssh/id_rsa
    # After 2c verifies, remove the retired 'ssh-rsa AAAA...' line from the server's
    # ~/.ssh/authorized_keys (keep a cp -a backup of the file before editing).
  3. Confirm resolution: non-interactive key-only auth plus an effective-config sanity check.
    $ ssh -o BatchMode=yes admin@build01 'echo AUTH_OK'; echo rc=$?
    AUTH_OK
    rc=0
    $ sudo sshd -T | grep -iE 'pubkeyacceptedalgorithms|hostkeyalgorithms'

    Exit status 0 with no password prompt proves the whole chain — key, algorithm negotiation, authorized_keys entry and permissions — is clean.

Multi-Distro Command & Path Matrix

Ubuntu / Debian

# Unit: ssh.service | config: /etc/ssh/sshd_config + /etc/ssh/sshd_config.d/*.conf
sudo journalctl -u ssh -S -1h | grep -iE 'userauth_pubkey|PubkeyAccepted'
printf 'PubkeyAcceptedAlgorithms +ssh-rsan' | sudo tee /etc/ssh/sshd_config.d/90-legacy-sha1.conf
sudo sshd -t && sudo systemctl reload ssh
sudo sshd -T | grep -i pubkeyacceptedalgorithms

RHEL / AlmaLinux / Rocky

# Unit: sshd.service | crypto-policies gates SHA-1 signatures system-wide
update-crypto-policies --show
sudo journalctl -u sshd -S -1h | grep -iE 'signature algorithm|crypto-policies'
# Scoped override (drop-ins load before the crypto-policies backend, so they win):
printf 'PubkeyAcceptedAlgorithms +ssh-rsan' | sudo tee /etc/ssh/sshd_config.d/90-legacy-sha1.conf
sudo sshd -t && sudo systemctl reload sshd
# System-wide alternative (affects every consumer, not only sshd):
sudo update-crypto-policies --set DEFAULT:SHA1 && sudo systemctl reload sshd

Arch Linux

# Unit: sshd.service | OpenSSH 10.x: ssh-rsa default-off, DSA compile-removed
sudo journalctl -u sshd -S -1h | grep -iE 'userauth_pubkey|PubkeyAccepted'
ssh -Q sig | grep -E '^(ssh-rsa|rsa-sha2)'
printf 'nPubkeyAcceptedAlgorithms +ssh-rsan' | sudo tee -a /etc/ssh/sshd_config
sudo sshd -t && sudo systemctl reload sshd

Alpine / Containers

# OpenRC host: rc-service sshd | container: /usr/sbin/sshd -D -e prints preauth rejects on stderr
apk info -e openssh-server || apk add openssh
printf 'nPubkeyAcceptedAlgorithms +ssh-rsan' >> /etc/ssh/sshd_config
sshd -t
rc-service sshd reload || /usr/sbin/sshd -D -e
# dropbear-based images (dropbear <2020.79 lacks rsa-sha2): apk upgrade dropbear
# Log: busybox syslogd writes sshd messages to /var/log/messages

Safety & Rollback Checks

Safety Check: Snapshot live config first: sudo cp -a /etc/ssh/sshd_config /etc/ssh/sshd_config.$(date +%F).bak. Never send changes live unverified — run sudo sshd -t (pure syntax test, no reload), then audit what will actually apply with sudo sshd -T, adding -C user=<user>,host=<host>,addr=<ip> when Match blocks exist. Keep your current SSH session open and prefer systemctl reload (SIGHUP): established sessions survive, so a failed reload is fixable from the live shell.

Rollback: move the drop-in aside instead of deleting it — sudo mv /etc/ssh/sshd_config.d/90-legacy-sha1.conf /root/ — re-run sshd -t, reload, and confirm with sudo sshd -T that the hardened default list is restored. Undo the RHEL subpolicy with sudo update-crypto-policies --set DEFAULT. Client-side host entries are reversed by deleting the PubkeyAcceptedAlgorithms line from ~/.ssh/config; verify the effective result with ssh -G <host>. Test key-only access with ssh -o BatchMode=yes so prompts never hang. Treat +ssh-rsa anywhere as bridge-only: SHA-1 collisions are practical, so schedule the override for removal once both peers negotiate rsa-sha2-256/512 or ed25519.

Frequently Asked Edge Cases

Do I have to regenerate an existing RSA key after upgrading to OpenSSH 9?

No. The ssh-rsa AAAA... blob in authorized_keys stays valid because rsa-sha2-256/512 signatures reuse the same RSA key; only the hash is renegotiated. Verify with ssh-keygen -lf ~/.ssh/id_rsa.pub; switching to ssh-keygen -t ed25519 -a 100 is hardening, not repair.

Why does ssh -o PubkeyAcceptedAlgorithms=+ssh-rsa succeed when the plain command fails?

It proves the peer accepts only SHA-1 RSA signatures: it is pre-OpenSSH 7.2, runs dropbear older than 2020.79, or its sshd restricts PubkeyAcceptedAlgorithms. Fix the lagging host, then drop the override. If the host key itself is rejected, the sibling error 'no matching host key type' is addressed by HostKeyAlgorithms +ssh-rsa.

Why do old DSA (ssh-dss) keys fail even after re-enabling algorithms?

OpenSSH 9.8 disabled DSA at compile time by default and 10.x removed it entirely, so ssh -Q key shows no ssh-dss on those builds. Deploy an RSA or ed25519 key via ssh-copy-id instead; DSA was always capped at 1024 bits.

References & Upstream Docs

  1. OpenSSH man pages: man 1 ssh, man 5 sshd_config (PubkeyAcceptedAlgorithms, HostKeyAlgorithms), man 8 sshd (-t, -T)
  2. OpenSSH Release Notes 8.8/9.8 - ssh-rsa default disablement and DSA compile-time removal: https://www.openssh.com/releasenotes.html
  3. RFC 8332 - Use of RSA Keys with SHA-2 256 and 512 Signature Algorithms in SSH
  4. RHEL 9 documentation: Using system-wide cryptographic policies (update-crypto-policies(8))

Related Concepts