Repository navigation
Description
It seems that when I have more than one key held by the agent, any authentication that would require anything but the first key would fail. The trace is copied down below. I also added some dedug info at the packet level. Could it be that there should not be a [service-request] following the [userauth-failure] with the wrong key, but directly a new [userauth-request]?
Thanks,
-Gellule
DEBUG:paramiko.transport:starting thread (client mode): 0x2514550L
INFO:paramiko.transport:Connected (version 2.0, client 3.2.9.1)
Write packet [kexinit], length 406
Read packet [ignore], length 5
Read packet [kexinit], length 461
DEBUG:paramiko.transport:kex algos:['diffie-hellman-group1-sha1'] server key:['ssh-dss'] client encrypt:['aes128-cbc', '3des-cbc', 'twofish128-cbc', 'cast128-cbc', 'twofish-cbc', 'blowfish-cbc', 'aes192-cbc', 'aes256-cbc', 'twofish192-cbc', 'twofish256-cbc', 'arcfour'] server encrypt:['aes128-cbc', '3des-cbc', 'twofish128-cbc', 'cast128-cbc', 'twofish-cbc', 'blowfish-cbc', 'aes192-cbc', 'aes256-cbc', 'twofish192-cbc', 'twofish256-cbc', 'arcfour'] client mac:['hmac-sha1', 'hmac-sha1-96', 'hmac-md5', 'hmac-md5-96'] server mac:['hmac-sha1', 'hmac-sha1-96', 'hmac-md5', 'hmac-md5-96'] client compress:['none', 'zlib'] server compress:['none', 'zlib'] client lang:[''] server lang:[''] kex follows?False
DEBUG:paramiko.transport:Ciphers agreed: local=aes128-cbc, remote=aes128-cbc
DEBUG:paramiko.transport:using kex diffie-hellman-group1-sha1; server key type ssh-dss; cipher: local aes128-cbc, remote aes128-cbc; mac: local hmac-sha1, remote hmac-sha1; compression: local none, remote none
Write packet [kex30], length 133
Read packet [ignore], length 5
Read packet [kex31], length 630
Write packet [newkeys], length 1
Read packet [ignore], length 5
Read packet [newkeys], length 1
DEBUG:paramiko.transport:Switch to new keys ...
DEBUG:paramiko.transport:Trying SSH agent key fbd3bc799a422891ffc58f9212539a13
Write packet [service-request], length 17
Read packet [ignore], length 5
Read packet [service-accept], length 17
DEBUG:paramiko.transport:userauth is OK
Write packet [userauth-request], length 550
Read packet [ignore], length 1005
Read packet [userauth-failure], length 24
INFO:paramiko.transport:Authentication (publickey) failed.
DEBUG:paramiko.transport:Trying SSH agent key 939d6a49f527e8f0c53e9ec509ff913a
Write packet [service-request], length 17
Read packet [ignore], length 5
Read packet [disconnect], length 54
INFO:paramiko.transport:Disconnect (code 2): Protocol error: packet 5 in interactive
paramiko.AuthenticationException: Authentication failed.
Activity
gellule commentedon Jul 5, 2011
See this thread for the real problem: https://fogbugz.bitvise.com/default.asp?WinSSHD.1.16148.4
Sending multiple service-request for userauth.
jansegre commentedon Jan 21, 2015
I am experiencing a very similar, if not the same, issue.
I got to this while using fabric and tracked it down to paramiko. My use case is connecting to a Mikrotik Router (which uses ROSSSH ssh server), while using publickey authentication.
These are the 3 most relevant logs, I have hidden the real IPs though.
Successful authentication with openssh client:
Notice how openssh tries the rsa key first, it fails but it is able to continue trying.
Successful authentication with paramiko, when using
allow_agent=False:Failed authentication with paramiko, when
allow_agentdefaults toTrue:The exceptions happens because of the disconnection, I had to go through the code to learn that.
The disconnect code, is for
protocol error, the log on the original issue report seems to help a bit more and state that.For my use case it's complicated to make a workaround since I'm not directly using paramiko, I'm using fabric. And also the connection part has to work for other hosts, some of which will use rsa keys and other dss keys.
Can anyone give any hint on how to proceed? Or any way I can help fix this bug? I'm not familiar with the SSH protocol specification.
Refactor of previous commit. Fixes paramiko#23, straight port of PR24.
corbie commentedon Nov 29, 2016
I can confirm this issue also affects SSH version 1.99, client Cisco-1.25 (ASA OS 9.6.2). Paramiko sends a new
SSH_MSG_SERVICE_REQUESTfor each key loaded from an ssh-agent, but the remote server expects the conversation to start with a singleSSH_MSG_SERVICE_REQUESTfollowed bySSH_MSG_USERAUTH_REQUESTmessage for each key. RFC 4252 Section 5 seems to support this:Abbreviated logs follow:
This is specifically affecting the asa_command module in Ansible 2.2 when using an encrypted private key with ssh-agent on OS X 10.12, Python 2.7.12. The workaround is to set key order manually, adding the required key to ssh-agent first; this ensures that the first
publickeyauthentication is successful.The code in #478 corrects this issue.
rarylson commentedon Dec 13, 2016
Hi,
I confirm this problem in my Mikrotik RouterOS 6 routers.
I've tested and reviewed the code in PR 478 (#478). It seems good and it fixed all my problems with Mikrotik routers.
zougloub commentedon Oct 12, 2017
A workaround when using gpg-agent is to edit
sshcontrolto put the desired key on top.It would be nice to be able to select the desired key from the agent, but even openssh doesn't seem to be able to do that (no config entry for that, similar to
IdentityFile).jean-christophe-manciot commentedon Dec 27, 2017
Same issue on:
I confirm that paramiko tries to connect with the first SSH key managed by gpg-agent, and fails to find a key supported by the remote device (Cisco ASAv) in the list of SSH keys available in sshcontrol.
Trying to connect with ansible/paramiko fails:
Trying to connect with openssh 7.6p1 succeeds:
If I move the required key in first position of ~/.gnupg/sshcontrol file, then this issue does not appear..
radssh commentedon Dec 29, 2017
Another impact of #387 it would appear. Specifically the remote switch (typically) dropping the connection on receiving a second
SSH_MSG_SERVICE_REQUESTmessage, when expecting the dialog to continue withSSH_MSG_USERAUTH_REQUEST.rarylson commentedon Feb 6, 2018
Hi, I proposed an improved version on the top of the fix proposed by @jansegre (it fixes more problems, when different auth methods are tried in a Mikrotik or Cisco router, for example).
I also verified that the commit passes in all Paramiko tests.
I also made a pull request to jansegre (in it's fork). But as bitprophet and radssh are working in a more general solution on #387, I'm not creating a new pull request in the mainstream.
However, I'm showing my changes here and I hope they can help.
ssbarnea commentedon Feb 18, 2018
Any chance of seeing this resolved? Somehow I just realised that if you happen to use more than one ssh key and ssh agent, paramiko is not for you.
The reordering of keys is not going to work because is almost impossible to know a-priory which ssh key is needed for a specific host.
Merge pull request paramiko#23 from ploxiln/putfo_stat_exc
bitprophet commentedon Apr 22, 2023
I have ended up taking a similar approach as in #387, to wit:
auth_xxxmethod until it sees that said attribute has been twiddled by aforementioned new handlerauth_xxxmethods, and then immediately hangs out and waits for the reply (so that, as before, this all appears to be blocking to the average user)I've tested this enough that I can eg send 2 bad passwords and 1 good one, and observe only 1x MSG_SERVICE_REQUEST gets sent, instead of 3x.
Next week will see it polished and further tested and released to my internal users for alpha testing; it will let us remove the code I gave them this past week to use an earlier alpha for #387 which allows user code to configure the auth flow, in this case to strip out agent keys they know will not succeed. Now, with this, they can drop that code already and not have golang targets blow up after auth failures.