Repository navigation
Closed as not planned
Closed as not planned
Copy link
Milestone
Description
OS: Fedora 33
Python: 3.9.2
paramiko==2.7.2
Code:
username = 'user'
hostname = 'localhost'
p_key = '/home/user/.ssh/id_rsa'
client = paramiko.SSHClient()
paramiko.util.log_to_file('/home/user/paramiko.log')
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(hostname, username=username, key_filename=p_key)
Error message:
Traceback (most recent call last):
File "/home/user/test.py", line 10, in <module>
client.connect(hostname, username=username, key_filename=p_key)
File "/usr/lib/python3.9/site-packages/paramiko/client.py", line 435, in connect
self._auth(
File "/usr/lib/python3.9/site-packages/paramiko/client.py", line 680, in _auth
self._transport.auth_publickey(username, key)
File "/usr/lib/python3.9/site-packages/paramiko/transport.py", line 1580, in auth_publickey
return self.auth_handler.wait_for_response(my_event)
File "/usr/lib/python3.9/site-packages/paramiko/auth_handler.py", line 236, in wait_for_response
raise e
File "/usr/lib/python3.9/site-packages/paramiko/transport.py", line 2109, in run
handler(self.auth_handler, m)
File "/usr/lib/python3.9/site-packages/paramiko/auth_handler.py", line 298, in _parse_service_accept
sig = self.private_key.sign_ssh_data(blob)
File "/usr/lib/python3.9/site-packages/paramiko/dsskey.py", line 108, in sign_ssh_data
key = dsa.DSAPrivateNumbers(
File "/usr/lib64/python3.9/site-packages/cryptography/hazmat/primitives/asymmetric/dsa.py", line 250, in private_key
return backend.load_dsa_private_numbers(self)
File "/usr/lib64/python3.9/site-packages/cryptography/hazmat/backends/openssl/backend.py", line 852, in load_dsa_private_numbers
dsa._check_dsa_private_numbers(numbers)
File "/usr/lib64/python3.9/site-packages/cryptography/hazmat/primitives/asymmetric/dsa.py", line 147, in _check_dsa_private_numbers
_check_dsa_parameters(parameters)
File "/usr/lib64/python3.9/site-packages/cryptography/hazmat/primitives/asymmetric/dsa.py", line 139, in _check_dsa_parameters
raise ValueError("q must be exactly 160, 224, or 256 bits long")
ValueError: q must be exactly 160, 224, or 256 bits long
paramiko.log contents:
DEB [20210415-13:22:01.677] thr=1 paramiko.transport: starting thread (client mode): 0x56767ee0
DEB [20210415-13:22:01.677] thr=1 paramiko.transport: Local version/idstring: SSH-2.0-paramiko_2.7.2
DEB [20210415-13:22:01.690] thr=1 paramiko.transport: Remote version/idstring: SSH-2.0-OpenSSH_8.4
INF [20210415-13:22:01.690] thr=1 paramiko.transport: Connected (version 2.0, client OpenSSH_8.4)
DEB [20210415-13:22:01.692] thr=1 paramiko.transport: kex algos:['curve25519-sha256', '[email protected]', 'ecdh-sha2-nistp256', 'ecdh-sha2-nistp384', 'ecdh-sha2-nistp521', 'diffie-hellman-group-exchange-sha256', 'diffie-hellman-group14-sha256', 'diffie-hellman-group16-sha512', 'diffie-hellman-group18-sha512'] server key:['rsa-sha2-512', 'rsa-sha2-256', 'ecdsa-sha2-nistp256', 'ssh-ed25519'] client encrypt:['[email protected]', '[email protected]', 'aes256-ctr', '[email protected]', 'aes128-ctr'] server encrypt:['[email protected]', '[email protected]', 'aes256-ctr', '[email protected]', 'aes128-ctr'] client mac:['[email protected]', '[email protected]', '[email protected]', '[email protected]', 'hmac-sha2-256', 'hmac-sha1', '[email protected]', 'hmac-sha2-512'] server mac:['[email protected]', '[email protected]', '[email protected]', '[email protected]', 'hmac-sha2-256', 'hmac-sha1', '[email protected]', 'hmac-sha2-512'] client compress:['none', '[email protected]'] server compress:['none', '[email protected]'] client lang:[''] server lang:[''] kex follows?False
DEB [20210415-13:22:01.692] thr=1 paramiko.transport: Kex agreed: [email protected]
DEB [20210415-13:22:01.692] thr=1 paramiko.transport: HostKey agreed: ssh-ed25519
DEB [20210415-13:22:01.692] thr=1 paramiko.transport: Cipher agreed: aes128-ctr
DEB [20210415-13:22:01.692] thr=1 paramiko.transport: MAC agreed: hmac-sha2-256
DEB [20210415-13:22:01.692] thr=1 paramiko.transport: Compression agreed: none
DEB [20210415-13:22:01.702] thr=1 paramiko.transport: kex engine KexCurve25519 specified hash_algo <built-in function openssl_sha256>
DEB [20210415-13:22:01.703] thr=1 paramiko.transport: Switch to new keys ...
DEB [20210415-13:22:01.703] thr=2 paramiko.transport: Adding ssh-ed25519 host key for localhost: b'cd253a4f02710db1cd015a0987e55808'
DEB [20210415-13:22:01.731] thr=2 paramiko.transport: Trying discovered key b'f04a122496865c894b5df6d1eb07bceb' in /home/user/.ssh/id_rsa
DEB [20210415-13:22:01.731] thr=1 paramiko.transport: userauth is OK
INF [20210415-13:22:01.750] thr=1 paramiko.transport: Authentication (publickey) failed.
DEB [20210415-13:22:01.751] thr=2 paramiko.transport: Trying discovered key b'd97f81e10ee73700ec5c1484ce07af50' in /home/user/.ssh/id_rsa
DEB [20210415-13:22:01.751] thr=1 paramiko.transport: userauth is OK
ERR [20210415-13:22:01.752] thr=1 paramiko.transport: Unknown exception: q must be exactly 160, 224, or 256 bits long
ERR [20210415-13:22:01.753] thr=1 paramiko.transport: Traceback (most recent call last):
ERR [20210415-13:22:01.754] thr=1 paramiko.transport: File "/usr/lib/python3.9/site-packages/paramiko/transport.py", line 2109, in run
ERR [20210415-13:22:01.754] thr=1 paramiko.transport: handler(self.auth_handler, m)
ERR [20210415-13:22:01.754] thr=1 paramiko.transport: File "/usr/lib/python3.9/site-packages/paramiko/auth_handler.py", line 298, in _parse_service_accept
ERR [20210415-13:22:01.754] thr=1 paramiko.transport: sig = self.private_key.sign_ssh_data(blob)
ERR [20210415-13:22:01.754] thr=1 paramiko.transport: File "/usr/lib/python3.9/site-packages/paramiko/dsskey.py", line 108, in sign_ssh_data
ERR [20210415-13:22:01.754] thr=1 paramiko.transport: key = dsa.DSAPrivateNumbers(
ERR [20210415-13:22:01.754] thr=1 paramiko.transport: File "/usr/lib64/python3.9/site-packages/cryptography/hazmat/primitives/asymmetric/dsa.py", line 250, in private_key
ERR [20210415-13:22:01.754] thr=1 paramiko.transport: return backend.load_dsa_private_numbers(self)
ERR [20210415-13:22:01.754] thr=1 paramiko.transport: File "/usr/lib64/python3.9/site-packages/cryptography/hazmat/backends/openssl/backend.py", line 852, in load_dsa_private_numbers
ERR [20210415-13:22:01.754] thr=1 paramiko.transport: dsa._check_dsa_private_numbers(numbers)
ERR [20210415-13:22:01.754] thr=1 paramiko.transport: File "/usr/lib64/python3.9/site-packages/cryptography/hazmat/primitives/asymmetric/dsa.py", line 147, in _check_dsa_private_numbers
ERR [20210415-13:22:01.754] thr=1 paramiko.transport: _check_dsa_parameters(parameters)
ERR [20210415-13:22:01.754] thr=1 paramiko.transport: File "/usr/lib64/python3.9/site-packages/cryptography/hazmat/primitives/asymmetric/dsa.py", line 139, in _check_dsa_parameters
ERR [20210415-13:22:01.754] thr=1 paramiko.transport: raise ValueError("q must be exactly 160, 224, or 256 bits long")
ERR [20210415-13:22:01.754] thr=1 paramiko.transport: ValueError: q must be exactly 160, 224, or 256 bits long
ERR [20210415-13:22:01.754] thr=1 paramiko.transport:
Reacted by jjjj326562
Activity
ploxiln commentedon Apr 17, 2021
I think this would be fixed by #1606
trewest commentedon Apr 17, 2021
Just tried with that branch
The error message now changed to:
paramiko.log:
Just to prove that my SSH key is in authorized_keys:
acerv commentedon Apr 22, 2022
Hi! I'm having the exact same issue in 2.10.3. Is it going to be fixed?
bskinn commentedon Apr 22, 2022
Hi, @acerv -- it will be, currently planned for the next bugfix release (as per the issue milestone). No specific timeline is available for that release, thought, as it depends on the balance of tasks for @bitprophet among paramiko, fabric and invoke, and what fits in his weekly chunk of OSS time.
linw1995 commentedon May 5, 2022
Hi! I'm having the exact same issue in
2.10.4. Is it going to be fixed? Or there are other ways to resolve this problem temporarily?bskinn commentedon May 5, 2022
Yes, this will be fixed in an upcoming release, see my comment above. It doesn't appear that any workarounds have been identified yet; you can follow this issue to see if any get posted here.
KennethWilke commentedon May 5, 2022
Found my way here from running into the same issue. This comment mentioned that they didn't run into this issue specifically with
paramiko==2.8.1:fabric/fabric#2182 (comment)
This seemed to be the simplest way to resolve the problem temporarily for my use case. @linw1995 maybe this could work for you as well while we're waiting for a released fix.
lgblkb commentedon May 20, 2022
This helped me:
ksrangarajan commentedon May 24, 2022
Will be glad to know if there is any timeline available for fix to be made available?
bskinn commentedon May 24, 2022
@ksrangarajan -- It's in line for a bugfix release, but unfortunately there's no specific timeline. It depends on bitprophet's prioritization between paramiko, invoke and fabric, and on what he can fit in his weekly OSS time allotment.
bskinn commentedon May 24, 2022
For easy crossref: Per @ploxiln, this may be fixed by #1606, which in turn was aimed at fixing #1590.
markios commentedon Jul 20, 2022
Is there any update on this, or when it will likely be fixed?
bskinn commentedon Jul 22, 2022
Yeah, sorry for the delay on things key-related. Right now bitprophet's first priority is a new release that drops Python 2 and older versions of Python 3. I believe a ~complete rework of the key-handing and auth code (see, e.g., #387) is the first priority after that. No idea on a specific timeline, unfortunately -- like I noted above, his weekly OSS time is split among paramiko, invoke and fabric, and so everything is mutually prioritized among the three projects.
jackcasey-visier commentedon Sep 27, 2022
A workaround we've been using, is to load the key directly and pass it to the
SSHClientconnection viapkey.As an example:
Getting key:
Usage:
I haven't dug into the source much, but it appears this is bypassing the problematic key type detection step, and enforces use of RSA directly :)
Fix ValueError("q must be exactly ... bits long")
Fix ValueError("q must be exactly ... bits long")
Fix ValueError("q must be exactly ... bits long")
huaiguoguo commentedon Jun 4, 2023
I'm having the same issue in 2.12.0, when it will be fixed ?
@bskinn @alex @bitprophet
bskinn commentedon Jun 5, 2023
Work is in progress on this, in stages. Please check out the experimental new features described in the 3.2.0 paramiko CHANGELOG (including the new
OpenSSHAuthStrategyimplementation in Fabric 3.1.0).I'm not deeply familiar with what the current features enable, so I can't say for sure whether they fix this use case. We would greatly appreciate any investigation you might be able to do and report back here, though.
Fix paramiko incorrectly auto-detects private key method
Fix paramiko incorrectly auto-detects private key method
Fix paramiko incorrectly auto-detects private key method (#2221)
jshen28 commentedon Oct 24, 2024
I was hit by this stack trace because a wrong user name is given.
cjwatson commentedon Aug 13, 2025
I happened to notice that support for DSA keys has been (reasonably!) dropped in Paramiko 4.0.0. Does that effectively close this bug, since it isn't going to mishandle RSA keys as DSA any more when it no longer has DSA support? Or is there some deeper issue as yet unaddressed?
bskinn commentedon Aug 13, 2025
Thanks for surfacing this, @cjwatson!
Seems likely so; I'll close now, and we can revisit if needed.