You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Bad authentication type when 'Authentications that can continue' not supplied #787
I was able to SSH into the switch from Putty and supply name/pass without issue. Finally tested 'ssh -v' from a linux shell, and discovered that the working switch transmitted a line for 'Authentications that can continue' just before asking for the password, and the switch that was failing to connect with paramiko was NOT sending this line.
Additionally, there is no line for 'Next authentication method', which may be more critical here.
I have to assume that paramiko not seeing this line is causing an instant failure, and I'm not seeing a way to work around this issue.
Switch is running its latest firmware, issue being reported to manufacturer.
Paramiko does not make use of the ssh command line client, so not seeing the corresponding messages as you see from ssh -v is not unexpected. You can enable more verbose logging in your script by adding this right after the import lines:
The ssh protocol for authentication can get rather tricky, and from limited experience with switches, they notoriously add their own creative interpretations of the protocol (Nonstandard platforms label). The added debug output might shed more light on what's happening behind the scenes.
It seems odd that the allowed_types list only includes publickey, and not password or keyboard-interactive, but that could be a byproduct of the list only being populated with the info from the most recent authentication attempted. The debug logging should include the info from each stage along the way.
I've added the lines suggested, here is the output when connecting to a problem switch. Note that it is using OpenSSH 5.9, not sure if that is relevant or not.
And again, I can SSH from the command line or a terminal app and log in with username/password just fine. Ultimately what I need is some way to tell paramiko to ignore the error and try connecting anyway.
DEBUG:paramiko.transport:starting thread (client mode): 0x3442eb0
DEBUG:paramiko.transport:Local version/idstring: SSH-2.0-paramiko_2.0.1
DEBUG:paramiko.transport:Remote version/idstring: SSH-2.0-OpenSSH_5.9p1.RL
INFO:paramiko.transport:Connected (version 2.0, client OpenSSH_5.9p1.RL)
DEBUG:paramiko.transport:kex algos:['diffie-hellman-group-exchange-sha1', 'diffie-hellman-group1-sha1'] server key:['ssh-rsa', 'ssh-dss'] client encrypt:['aes128-cbc', '3des-cbc', 'arcfour', 'aes192-cbc', 'aes256-cbc'] server encrypt:['aes128-cbc', '3des-cbc', 'arcfour', 'aes192-cbc', 'aes256-cbc'] client mac:['hmac-sha1', 'hmac-md5'] server mac:['hmac-sha1', 'hmac-md5'] client compress:['none'] server compress:['none'] client lang:[''] server lang:[''] kex follows?False
DEBUG:paramiko.transport:Kex agreed: diffie-hellman-group1-sha1
DEBUG:paramiko.transport:Cipher agreed: aes128-cbc
DEBUG:paramiko.transport:MAC agreed: hmac-md5
DEBUG:paramiko.transport:Compression agreed: none
DEBUG:paramiko.transport:kex engine KexGroup1 specified hash_algo
DEBUG:paramiko.transport:Switch to new keys ...
DEBUG:paramiko.transport:Adding ssh-rsa host key for 192.168.1.2: b'7867c6f86c650e56dedfe5d62a79cff0'
DEBUG:paramiko.transport:userauth is OK
DEBUG:paramiko.transport:Authentication type (password) not permitted.
DEBUG:paramiko.transport:Allowed methods: ['publickey']
Traceback (most recent call last):
File "python\ssh.py", line 35, in
remote_conn_pre.connect(ip, username=username, password=password, look_for_keys=False, allow_agent=False)
File "C:\Users\wrightj\AppData\Local\Programs\Python\Python35-32\lib\site-packages\paramiko\client.py", line 380, in connect
look_for_keys, gss_auth, gss_kex, gss_deleg_creds, gss_host)
File "C:\Users\wrightj\AppData\Local\Programs\Python\Python35-32\lib\site-packages\paramiko\client.py", line 603, in _auth
raise saved_exception
File "C:\Users\wrightj\AppData\Local\Programs\Python\Python35-32\lib\site-packages\paramiko\client.py", line 590, in _auth
self._transport.auth_password(username, password)
File "C:\Users\wrightj\AppData\Local\Programs\Python\Python35-32\lib\site-packages\paramiko\transport.py", line 1263, in auth_password
return self.auth_handler.wait_for_response(my_event)
File "C:\Users\wrightj\AppData\Local\Programs\Python\Python35-32\lib\site-packages\paramiko\auth_handler.py", line 208, in wait_for_response
raise e
paramiko.ssh_exception.BadAuthenticationType: ('Bad authentication type', ['publickey']) (allowed_types=['publickey'])
DEBUG:paramiko.transport:EOF in transport thread
Here is the full verbose log when doing an ssh from the command line, the banner for the switch and login prompt would show after the last line below:
[root@localhost ~]# ssh -v [email protected]
OpenSSH_5.3p1, OpenSSL 1.0.0-fips 29 Mar 2010
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Connecting to 192168.1.2 [192168.1.2] port 22.
debug1: Connection established.
debug1: permanently_set_uid: 0/0
debug1: identity file /root/.ssh/identity type -1
debug1: identity file /root/.ssh/id_rsa type -1
debug1: identity file /root/.ssh/id_dsa type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.9p1.RL
debug1: match: OpenSSH_5.9p1.RL pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.3
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-cbc hmac-md5 none
debug1: kex: client->server aes128-cbc hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Host '192168.1.2' is known and matches the RSA host key.
debug1: Found key in /root/.ssh/known_hosts:2
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentication succeeded (none).
debug1: channel 0: new [client-session]
debug1: Requesting [email protected]
debug1: Entering interactive session.
debug1: Sending environment.
debug1: Sending env LANG = en_US.UTF-8
The 'Authentication succeeded' line in there may be why the switch isn't sending out 'Authentications that can continue' and related messages, it is just skipping over that whole thing.
Looks like the server (in the latest ssh -v attempt) is letting you in without a publickey or password at all.
debug1: Authentication succeeded (none).
This might be due to some host-based authentication setup on the switch, or it may be a gaping security flaw. When the paramiko script offers a password to authenticate, the server is sending back a rejection of the password, not because the password is incorrect, but because the server itself is not configured to accept password authentication (possibly on a user by user basis), and indicating back to the client that the available methods that can be used consist of the single type 'publickey'.
If the switch config can be update to allow password authentication (and possibly consider turning off auth_none, if that's not intentional), then the paramiko Client should be allowed to authenticate via password.
That discussion thread seems to be the same type of issue I'm seeing here, but I'm a bit confused on how exactly to implement the workaround given at the end of that thread in my script. Being new at Python isn't helping. ;)
The SSH implementation on this switch is definitely buggy, and is legacy equipment. When the SSH session actually connects, I can enter a username/password after the banner, and I'm logged in, regardless of any credentials I supply up front to connect. It isn't possible to change much of the SSH config because it's all hidden under the hood, and not part of the CLI commands available.
If you patched that in as is, you would (probably) fix the authentication to your legacy switch, but break it for the currently working hosts. It would replace the authentication code with only the attempt to try auth_none.
Try adding these lines after all your imports:
class patched_SSHClient(paramiko.SSHClient):
def _auth(self, username, password, *args):
if not password:
try:
self._transport.auth_none(username)
return
except paramiko.BadAuthenticationType:
pass
paramiko.SSHClient._auth(self, username, password, *args)
Then change the code afterwards to use patched_SSHClient instead of paramiko.SSHClient, and for connections that support "none" as a valid authentication type, pass a blank password into the connect() call. If you do pass in a password to use, it will pass through to the original paramiko SSHClient authentication.
I am seeing this error attempting to do replicate the example code shown in the documentation, I noticed that many people have the same issue, have you worked out a solution for this problem ?
Activity
radssh commentedon Jul 26, 2016
Paramiko does not make use of the ssh command line client, so not seeing the corresponding messages as you see from
ssh -vis not unexpected. You can enable more verbose logging in your script by adding this right after the import lines:The ssh protocol for authentication can get rather tricky, and from limited experience with switches, they notoriously add their own creative interpretations of the protocol (Nonstandard platforms label). The added debug output might shed more light on what's happening behind the scenes.
It seems odd that the allowed_types list only includes
publickey, and notpasswordorkeyboard-interactive, but that could be a byproduct of the list only being populated with the info from the most recent authentication attempted. The debug logging should include the info from each stage along the way.Jim-Wright commentedon Jul 26, 2016
I've added the lines suggested, here is the output when connecting to a problem switch. Note that it is using OpenSSH 5.9, not sure if that is relevant or not.
And again, I can SSH from the command line or a terminal app and log in with username/password just fine. Ultimately what I need is some way to tell paramiko to ignore the error and try connecting anyway.
DEBUG:paramiko.transport:starting thread (client mode): 0x3442eb0
DEBUG:paramiko.transport:Local version/idstring: SSH-2.0-paramiko_2.0.1
DEBUG:paramiko.transport:Remote version/idstring: SSH-2.0-OpenSSH_5.9p1.RL
INFO:paramiko.transport:Connected (version 2.0, client OpenSSH_5.9p1.RL)
DEBUG:paramiko.transport:kex algos:['diffie-hellman-group-exchange-sha1', 'diffie-hellman-group1-sha1'] server key:['ssh-rsa', 'ssh-dss'] client encrypt:['aes128-cbc', '3des-cbc', 'arcfour', 'aes192-cbc', 'aes256-cbc'] server encrypt:['aes128-cbc', '3des-cbc', 'arcfour', 'aes192-cbc', 'aes256-cbc'] client mac:['hmac-sha1', 'hmac-md5'] server mac:['hmac-sha1', 'hmac-md5'] client compress:['none'] server compress:['none'] client lang:[''] server lang:[''] kex follows?False
DEBUG:paramiko.transport:Kex agreed: diffie-hellman-group1-sha1
DEBUG:paramiko.transport:Cipher agreed: aes128-cbc
DEBUG:paramiko.transport:MAC agreed: hmac-md5
DEBUG:paramiko.transport:Compression agreed: none
DEBUG:paramiko.transport:kex engine KexGroup1 specified hash_algo
DEBUG:paramiko.transport:Switch to new keys ...
DEBUG:paramiko.transport:Adding ssh-rsa host key for 192.168.1.2: b'7867c6f86c650e56dedfe5d62a79cff0'
DEBUG:paramiko.transport:userauth is OK
DEBUG:paramiko.transport:Authentication type (password) not permitted.
DEBUG:paramiko.transport:Allowed methods: ['publickey']
Traceback (most recent call last):
File "python\ssh.py", line 35, in
remote_conn_pre.connect(ip, username=username, password=password, look_for_keys=False, allow_agent=False)
File "C:\Users\wrightj\AppData\Local\Programs\Python\Python35-32\lib\site-packages\paramiko\client.py", line 380, in connect
look_for_keys, gss_auth, gss_kex, gss_deleg_creds, gss_host)
File "C:\Users\wrightj\AppData\Local\Programs\Python\Python35-32\lib\site-packages\paramiko\client.py", line 603, in _auth
raise saved_exception
File "C:\Users\wrightj\AppData\Local\Programs\Python\Python35-32\lib\site-packages\paramiko\client.py", line 590, in _auth
self._transport.auth_password(username, password)
File "C:\Users\wrightj\AppData\Local\Programs\Python\Python35-32\lib\site-packages\paramiko\transport.py", line 1263, in auth_password
return self.auth_handler.wait_for_response(my_event)
File "C:\Users\wrightj\AppData\Local\Programs\Python\Python35-32\lib\site-packages\paramiko\auth_handler.py", line 208, in wait_for_response
raise e
paramiko.ssh_exception.BadAuthenticationType: ('Bad authentication type', ['publickey']) (allowed_types=['publickey'])
DEBUG:paramiko.transport:EOF in transport thread
Jim-Wright commentedon Jul 26, 2016
Here is the full verbose log when doing an ssh from the command line, the banner for the switch and login prompt would show after the last line below:
[root@localhost ~]# ssh -v [email protected]
OpenSSH_5.3p1, OpenSSL 1.0.0-fips 29 Mar 2010
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Connecting to 192168.1.2 [192168.1.2] port 22.
debug1: Connection established.
debug1: permanently_set_uid: 0/0
debug1: identity file /root/.ssh/identity type -1
debug1: identity file /root/.ssh/id_rsa type -1
debug1: identity file /root/.ssh/id_dsa type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.9p1.RL
debug1: match: OpenSSH_5.9p1.RL pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.3
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-cbc hmac-md5 none
debug1: kex: client->server aes128-cbc hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Host '192168.1.2' is known and matches the RSA host key.
debug1: Found key in /root/.ssh/known_hosts:2
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentication succeeded (none).
debug1: channel 0: new [client-session]
debug1: Requesting [email protected]
debug1: Entering interactive session.
debug1: Sending environment.
debug1: Sending env LANG = en_US.UTF-8
The 'Authentication succeeded' line in there may be why the switch isn't sending out 'Authentications that can continue' and related messages, it is just skipping over that whole thing.
radssh commentedon Jul 26, 2016
Looks like the server (in the latest
ssh -vattempt) is letting you in without a publickey or password at all.This might be due to some host-based authentication setup on the switch, or it may be a gaping security flaw. When the paramiko script offers a password to authenticate, the server is sending back a rejection of the password, not because the password is incorrect, but because the server itself is not configured to accept password authentication (possibly on a user by user basis), and indicating back to the client that the available methods that can be used consist of the single type 'publickey'.
If the switch config can be update to allow password authentication (and possibly consider turning off auth_none, if that's not intentional), then the paramiko Client should be allowed to authenticate via password.
Alternatively, see this stackoverflow discussion that looks very much like what you are encountering.
Jim-Wright commentedon Jul 26, 2016
That discussion thread seems to be the same type of issue I'm seeing here, but I'm a bit confused on how exactly to implement the workaround given at the end of that thread in my script. Being new at Python isn't helping. ;)
The SSH implementation on this switch is definitely buggy, and is legacy equipment. When the SSH session actually connects, I can enter a username/password after the banner, and I'm logged in, regardless of any credentials I supply up front to connect. It isn't possible to change much of the SSH config because it's all hidden under the hood, and not part of the CLI commands available.
radssh commentedon Jul 27, 2016
If you patched that in as is, you would (probably) fix the authentication to your legacy switch, but break it for the currently working hosts. It would replace the authentication code with only the attempt to try auth_none.
Try adding these lines after all your imports:
Then change the code afterwards to use patched_SSHClient instead of paramiko.SSHClient, and for connections that support "none" as a valid authentication type, pass a blank password into the connect() call. If you do pass in a password to use, it will pass through to the original paramiko SSHClient authentication.
Jim-Wright commentedon Aug 1, 2016
Yes, that's working for me. Thanks so much!
steelliberty commentedon Jul 23, 2017
I am seeing this error attempting to do replicate the example code shown in the documentation, I noticed that many people have the same issue, have you worked out a solution for this problem ?
Here is the simple code -
from paramiko.client import *
client = SSHClient()
client.load_system_host_keys()
client.set_missing_host_key_policy(AutoAddPolicy())
client.connect(myhost, password=my_ssh_key_password)
stdin, stdout, stderr = client.exec_command('ls -l')
here is the result.
paramiko.ssh_exception.BadAuthenticationType: ('Bad authentication type', ['publickey']) (allowed_types=['publickey'])
thank you
rapavin commentedon Apr 20, 2018
i have a similar problem, the switch has 2 line vty commands and no transport input line.
i cannot use ansible or paramiko to get inside it.
it looks like a connection timeout or a port 22 access problem.
please help
vector-mj commentedon Jul 31, 2022
@steelliberty
You must also pass your private ssh key path to client.connect()