Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Security and hardening

Paramiko key login fails after agreeing on rsa-sha2-512

ErrorAgreed upon 'rsa-sha2-512' pubkey algorithm

Short answer

Since Paramiko 2.9 an RSA key is signed with rsa-sha2-512 or rsa-sha2-256 instead of SHA-1. A server that does not accept those signatures rejects the key even though it is correct. Disable the SHA-2 variants for that host with disabled_algorithms, or make the server accept rsa-sha2.

  • Applies to Paramiko 3.x, Python 3.13, OpenSSH 9.x
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Turn on Paramiko's log and read which algorithm it chose and what the server answered.

    import logging
    logging.basicConfig(level=logging.DEBUG)
    logging.getLogger("paramiko").setLevel(logging.DEBUG)
  2. 2Match what you see, then jump to its fix

    1. 1The server's sshd log says unsupported public key algorithm: rsa-sha2-512 and the same key works with a plain ssh clientThe server cannot verify SHA-2 RSA signaturesFix
    2. 2You control the server, it is recent, and sshd rejects rsa-sha2-512 anywayThe server's PubkeyAcceptedAlgorithms excludes the SHA-2 variantsFix

What does the error look like?

  • Agreed upon 'rsa-sha2-512' pubkey algorithm
  • paramiko.ssh_exception.AuthenticationException: Authentication failed.
  • unsupported public key algorithm: rsa-sha2-512

Cause 1 of 2

The server cannot verify SHA-2 RSA signatures

1Check

Paramiko 2.9.0 added rsa-sha2-256 and rsa-sha2-512 support and prefers them over legacy ssh-rsa. If the server does not send server-sig-algs, Paramiko tries the first one anyway. Compare with what the server accepts.

ssh -vv user@example.com 2>&1 | grep -i 'server-sig-algs\|rsa-sha2\|ssh-rsa'

2Fix

For this one host, tell Paramiko not to use the SHA-2 variants. This works on 2.9 to 4.x. Paramiko 5.0.0 removed SHA-1 RSA support altogether, so on 5.x this workaround leaves no RSA signature to use and the server has to be updated instead.

client.connect(
    "legacy.example.com",
    username="deploy",
    key_filename="/home/deploy/.ssh/id_rsa",
    disabled_algorithms={"keys": ["rsa-sha2-256", "rsa-sha2-512"]},
)

3Verify

Connect again with logging on. Authentication should now succeed on the first key.

python connect_test.py

Confirmed by paramiko.org

Did this fix it?

Cause 2 of 2

The server's PubkeyAcceptedAlgorithms excludes the SHA-2 variants

1Check

sshd only accepts the signature algorithms listed in PubkeyAcceptedAlgorithms. Print the list the server really uses and the list your OpenSSH supports.

sudo sshd -T | grep -i pubkeyacceptedalgorithms
ssh -Q PubkeyAcceptedAlgorithms

2Fix

Add the SHA-2 RSA names back to the option in /etc/ssh/sshd_config (or a drop-in file), test the file, and reload sshd.

# /etc/ssh/sshd_config.d/10-rsa-sha2.conf
PubkeyAcceptedAlgorithms +rsa-sha2-256,rsa-sha2-512

sudo sshd -t && sudo systemctl reload ssh

3Verify

Run sshd -T again and check both names are listed, then retry the Paramiko login.

sudo sshd -T | grep -i pubkeyacceptedalgorithms

Confirmed by man.openbsd.org

Did this fix it?

How do I stop it coming back?

  • Keep OpenSSH on managed servers current so SHA-2 RSA signatures are accepted.
  • Pin disabled_algorithms per host in code, not globally, so only the old server gets the workaround.
  • Note the Paramiko version in your lock file; behaviour around RSA algorithms changed across 2.9 and 5.0.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.