Skip to content

BadAuthenticationType or SSHException when no authentication method needed #1448

Open

Description

@deed02392

I believe this issue may be related to #787.

Basically, although OpenSSH's client succeeds:

debug1: Authentication succeeded (none).

Trying to connect with Paramiko either with generic password or None as password does not work.

I think that None and disabling key based authentication should work, indicating to the client library that no authentication method is the expected.

>>> ssh.connect(hostname='', username='root', password='Password', port=48409, timeout=30, compress=True, look_for_keys=False, allow_agent=False, auth_timeout=30, banner_timeout=30)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.7/site-packages/paramiko/client.py", line 437, in connect
    passphrase,
  File "/usr/local/lib/python3.7/site-packages/paramiko/client.py", line 749, in _auth
    raise saved_exception
  File "/usr/local/lib/python3.7/site-packages/paramiko/client.py", line 736, in _auth
    self._transport.auth_password(username, password)
  File "/usr/local/lib/python3.7/site-packages/paramiko/transport.py", line 1436, in auth_password
    return self.auth_handler.wait_for_response(my_event)
  File "/usr/local/lib/python3.7/site-packages/paramiko/auth_handler.py", line 250, in wait_for_response
    raise e
paramiko.ssh_exception.BadAuthenticationType: ('Bad authentication type', ['']) (allowed_types=[''])
>>> ssh.connect(hostname='', username='root', password=None, port=48409, timeout=30, compress=True, look_for_keys=False, allow_agent=False, auth_timeout=30, banner_timeout=30)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.7/site-packages/paramiko/client.py", line 437, in connect
    passphrase,
  File "/usr/local/lib/python3.7/site-packages/paramiko/client.py", line 750, in _auth
    raise SSHException("No authentication methods available")
paramiko.ssh_exception.SSHException: No authentication methods available

Activity

  1. ploxiln commented on May 29, 2019

    @ploxiln
    Contributor

    you could try #1106

  2. deed02392 commented on May 29, 2019

    @deed02392
    Author

    I don't think that is the issue. Otherwise when I tried password=None shouldn't it have just worked?

  3. ploxiln commented on May 29, 2019

    @ploxiln
    Contributor

    no, you would need to install and run with that pull request, which has not been merged

  4. ploxiln commented on May 29, 2019

    @ploxiln
    Contributor

    ... I have merged that PR to my fork a few days ago, just after my latest release though, so you could also try to install from the master branch of my fork as described here: https://github.com/ploxiln/paramiko-ng#installation

  5. deed02392 commented on May 29, 2019

    @deed02392
    Author

    No I mean, I don't think that PR will address this issue based on the description of it. It does not look relevant, am I mistaken?

  6. ploxiln commented on May 29, 2019

    @ploxiln
    Contributor

    That PR adds a call to self._transport.auth_none(username) first thing in the SSHClient, and that's what should detect that no password or publickey is needed. That return in the else clause should be activated for your case:

            try:
                self._transport.auth_none(username)
            except BadAuthenticationType as e:
                allowed_auth_methods = frozenset(e.allowed_types)
            else:
                # This server allows logging in with no auth
                return
  7. deed02392 commented on May 29, 2019

    @deed02392
    Author

    Ah I see now. This seems like it should be merged in this repo. Is this repo dead?

  8. somurzakov commented on Oct 5, 2023

    @somurzakov

    @deed02392
    Try this very simple workaround with auth_strategy=NoneAuth(''): works perfectly fine for me

    import paramiko
    from paramiko.auth_strategy import NoneAuth
    
    client = paramiko.SSHClient()
    client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    client.connect('localhost', port=10000, auth_strategy=NoneAuth(''))
    
    stdin, stdout, stderr = client.exec_command("whoami")
    print("".join(stdout.readlines()))
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions