Paramiko key login fails after agreeing on rsa-sha2-512
Agreed upon 'rsa-sha2-512' pubkey algorithmShort 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.
Fix it fast
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)2Match what you see, then jump to its fix
- 1
The 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
You control the server, it is recent, and sshd rejects rsa-sha2-512 anywayThe server's PubkeyAcceptedAlgorithms excludes the SHA-2 variantsFix
- 1
What does the error look like?
Agreed upon 'rsa-sha2-512' pubkey algorithmparamiko.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.pyConfirmed by paramiko.org
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 PubkeyAcceptedAlgorithms2Fix
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 ssh3Verify
Run sshd -T again and check both names are listed, then retry the Paramiko login.
sudo sshd -T | grep -i pubkeyacceptedalgorithmsConfirmed by man.openbsd.org
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:
- stegnor.comMy company site: 804 pages from a Python and Jinja generator, with 15 free browser tools.
- MenuloA restaurant discovery platform in Germany, kept current by a Python ingestion pipeline.
- ShopGoAn e-commerce aggregator with a Python scraping engine behind its catalog, past 10K Google Play downloads.
Related fixes
Security
Paramiko fails now and then with Error reading SSH protocol banner
paramiko.ssh_exception.SSHException: Error reading SSH protocol banner
Paramiko opens the TCP connection, then waits a short time for the server to send its SSH banner.
2 causes, each with a fixSecurity
PyJWT decode fails with ValueError: Could not deserialize key data
jwt.exceptions.InvalidKeyError
jwt.decode hands your key to the cryptography library, which must read it as PEM or SSH.
3 causes, each with a fixSecurity
PyJWT will not decode a Keycloak or RS256 token: algorithm errors
jwt.exceptions.MissingCryptographyError
RS256 and ES256 need the cryptography package, and jwt.decode only accepts the algorithms you list.
4 causes, each with a fixSecurity
Python rejects a self-signed certificate in the chain
certificate verify failed: self signed certificate in certificate chain (_ssl.c:992)
Python could not build a trusted path from the server certificate to a root it knows.
3 causes, each with a fixSecurity
Entra ID token request fails: the request body must contain the parameter 'grant_type'
AADSTS900144: The request body must contain the following parameter: 'grant_type'.
The token endpoint did not find grant_type in the form body of your POST.
3 causes, each with a fixSecurity
Angular HttpClient does not add the X-XSRF-TOKEN header to a request
403 Forbidden on POST, PUT or DELETE while GET works
Angular copies the XSRF-TOKEN cookie into an X-XSRF-TOKEN header only for mutating requests to the same origin, and only when the cookie is readable by script.
5 causes, each with a fix