Repository navigation
Open
Description
Are you using paramiko as a client or server?
Client
What feature(s) aren't working right?
SSH, Keys/auth
What version(s) of paramiko are you using?
3.3.1
What version(s) of Python are you using?
3.10.11
What operating system and version are you using?
Windows
If you're connecting as a client, which SSH server are you connecting to?
No response
If you're using paramiko as part of another tool, which tool/version?
NAPALM
What are you trying to do with paramiko?
Hello.
I have a router running JunOS 17.3R3-S2.2 and I can access this router via terminal with an SSH key that is encrypted. If I try to do this access via NAPALM, i get an auth error
"C:\Users\gabriel.lacerda\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\jnpr\junos\device.py", line 1374, in open
self._conn = netconf_ssh.connect(
File "C:\Users\gabriel.lacerda\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\ncclient\manager.py", line 176, in connect
return connect_ssh(*args, **kwds)
File "C:\Users\gabriel.lacerda\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\ncclient\manager.py", line 143, in connect_ssh
session.connect(*args, **kwds)
File "C:\Users\gabriel.lacerda\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\ncclient\transport\ssh.py", line 364, in connect
self._auth(username, password, key_filenames, allow_agent, look_for_keys)
File **"C:\Users\gabriel.lacerda\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\ncclient\transport\ssh.py", line 480, in _auth
raise AuthenticationError(repr(saved_exception))
ncclient.transport.errors.AuthenticationError: AuthenticationException('Authentication failed.')**
How are you trying to do it, and what's happening instead?
When I check the function raising the issue, it's using Paramiko for authentication, and I'm pretty sure that's where the problem happens:
for key_filename in key_filenames:
**for cls in (paramiko.RSAKey, paramiko.DSSKey, paramiko.ECDSAKey, paramiko.Ed25519Key):
try:
key = cls.from_private_key_file(key_filename, password)**
self.logger.debug("Trying key %s from %s",
hexlify(key.get_fingerprint()),
key_filename)
self._transport.auth_publickey(username, key)
return
except Exception as e:
saved_exception = e
self.logger.debug(e)
I enabled the debug in the NCC client, and this is what it says:
2023-09-04 10:18:10,126 - ncclient.transport.session - DEBUG - [host None session 0x1d4954cd930] <SSHSession(session, initial daemon)> created: client_capabilities=<dict_keyiterator object at 0x000001D4954F3150>
2023-09-04 10:18:10,145 - ncclient.transport.ssh - DEBUG - starting thread (client mode): 0x954cfa00
2023-09-04 10:18:10,146 - ncclient.transport.ssh - DEBUG - Local version/idstring: SSH-2.0-paramiko_3.3.1
2023-09-04 10:18:10,168 - ncclient.transport.ssh - DEBUG - Remote version/idstring: SSH-2.0-OpenSSH_6.9
2023-09-04 10:18:10,168 - ncclient.transport.ssh - INFO - Connected (version 2.0, client OpenSSH_6.9)
2023-09-04 10:18:10,185 - ncclient.transport.ssh - DEBUG - === Key exchange possibilities ===
2023-09-04 10:18:10,186 - ncclient.transport.ssh - DEBUG - kex algos: [email protected], ecdh-sha2-nistp256, ecdh-sha2-nistp384, ecdh-sha2-nistp521, diffie-hellman-group-exchange-sha256, diffie-hellman-group-exchange-sha1, diffie-hellman-group14-sha1, diffie-hellman-group1-sha1
2023-09-04 10:18:10,186 - ncclient.transport.ssh - DEBUG - server key: ssh-rsa, ssh-dss, ecdsa-sha2-nistp256, ssh-ed25519
2023-09-04 10:18:10,186 - ncclient.transport.ssh - DEBUG - client encrypt: [email protected], aes128-ctr, aes192-ctr, aes256-ctr, [email protected], [email protected], arcfour256, arcfour128, aes128-cbc, 3des-cbc, blowfish-cbc, cast128-cbc, aes192-cbc, aes256-cbc, arcfour, [email protected]
2023-09-04 10:18:10,187 - ncclient.transport.ssh - DEBUG - server encrypt: [email protected], aes128-ctr, aes192-ctr, aes256-ctr, [email protected], [email protected], arcfour256, arcfour128, aes128-cbc, 3des-cbc, blowfish-cbc, cast128-cbc, aes192-cbc, aes256-cbc, arcfour, [email protected]
2023-09-04 10:18:10,187 - ncclient.transport.ssh - DEBUG - client mac: [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], hmac-sha2-256, hmac-sha2-512, hmac-sha1, [email protected], [email protected], [email protected], [email protected], hmac-md5, hmac-ripemd160, [email protected], hmac-sha1-96, hmac-md5-96
2023-09-04 10:18:10,187 - ncclient.transport.ssh - DEBUG - server mac: [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], hmac-sha2-256, hmac-sha2-512, hmac-sha1, [email protected], [email protected], [email protected], [email protected], hmac-md5, hmac-ripemd160, [email protected], hmac-sha1-96, hmac-md5-96
2023-09-04 10:18:10,187 - ncclient.transport.ssh - DEBUG - client compress: none, [email protected]
2023-09-04 10:18:10,188 - ncclient.transport.ssh - DEBUG - server compress: none, [email protected]
2023-09-04 10:18:10,188 - ncclient.transport.ssh - DEBUG - client lang: <none>
2023-09-04 10:18:10,188 - ncclient.transport.ssh - DEBUG - server lang: <none>
2023-09-04 10:18:10,188 - ncclient.transport.ssh - DEBUG - kex follows: False
2023-09-04 10:18:10,188 - ncclient.transport.ssh - DEBUG - === Key exchange agreements ===
2023-09-04 10:18:10,188 - ncclient.transport.ssh - DEBUG - Kex: [email protected]
2023-09-04 10:18:10,189 - ncclient.transport.ssh - DEBUG - HostKey: ssh-ed25519
2023-09-04 10:18:10,189 - ncclient.transport.ssh - DEBUG - Cipher: aes128-ctr
2023-09-04 10:18:10,189 - ncclient.transport.ssh - DEBUG - MAC: hmac-sha2-256
2023-09-04 10:18:10,189 - ncclient.transport.ssh - DEBUG - Compression: none
2023-09-04 10:18:10,189 - ncclient.transport.ssh - DEBUG - === End of kex handshake ===
2023-09-04 10:18:10,314 - ncclient.transport.ssh - DEBUG - kex engine KexCurve25519 specified hash_algo <built-in function openssl_sha256>
2023-09-04 10:18:10,315 - ncclient.transport.ssh - DEBUG - Switch to new keys ...
**2023-09-04 10:18:10,416 - ncclient.transport.ssh - DEBUG - [host 172.17.0.51 session 0x1d4954cd930] OpenSSH private key file checkints do not match
2023-09-04 10:18:10,524 - ncclient.transport.ssh - DEBUG - [host 172.17.0.51 session 0x1d4954cd930] OpenSSH private key file checkints do not match
2023-09-04 10:18:10,640 - ncclient.transport.ssh - DEBUG - [host 172.17.0.51 session 0x1d4954cd930] OpenSSH private key file checkints do not match
2023-09-04 10:18:10,641 - ncclient.transport.ssh - DEBUG - [host 172.17.0.51 session 0x1d4954cd930] Invalid key
2023-09-04 10:18:10,751 - ncclient.transport.ssh - DEBUG - [host 172.17.0.51 session 0x1d4954cd930] OpenSSH private key file checkints do not match**
2023-09-04 10:18:10,762 - ncclient.transport.ssh - DEBUG - userauth is OK
This OpenSSH issue is raised by Paramiko in the pkey.py module, so my idea is that something is going wrong in the decryption and causing the issue. My SSH key password has special characters, and I thought that this might be the issue, but I don't know how to confirm. Can you give me some help?
Anything else?
No response
Activity
jun66j5 commentedon Sep 5, 2023
I don't think it is caused by password with special characters. I tried to create encrypted key with special characters and load the key, however the exception "invalid key" is not reproduced, at least.
Please confirm that the key file is able to be loaded by paramiko key classes like this: