Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need help connecting with domain user #343

Open
Suraj25P opened this issue Apr 11, 2022 · 1 comment
Open

Need help connecting with domain user #343

Suraj25P opened this issue Apr 11, 2022 · 1 comment

Comments

@Suraj25P
Copy link

import winrm
host = 'YourWindowsHost'
domain = 'YourDomain'
user = 'YourDomainUser'
password = 'YourPassword'
session = winrm.Session(host, auth=('{}@{}'.format(user,domain), password), transport='ntlm')

I have this above code but I'm not able to connect to windows host .. I have the right credentials as i am able to login manually.
I tried different transport methods
for ntlm,ssl and plaintext transport methods I get this below error:
<class 'winrm.exceptions.InvalidCredentialsError'>
<class 'Exception'> the specified credentials were rejected by the server

and for kerberos transport method I get :
<class 'winrm.exceptions.WinRMError'>
<class 'Exception'> requested auth method is kerberos, but requests_kerberos is not installed .....(i have installed requests_kerberos).

@ghost-ng
Copy link

ghost-ng commented Jun 4, 2023

this helped me, it had to do with the escape characters to properly format the domain & username entry.

self.username = f'{domain}\{username}' if domain else username

    p = Protocol(
        endpoint=endpoint,
        transport='ntlm',
        username=self.username,
        password=self.password,
        server_cert_validation='ignore',
        operation_timeout_sec=1000,  # Set timeout to 120 seconds
        read_timeout_sec=1200  # Set read timeout to 240 seconds (greater than operation timeout)

    )
    self.shell_id = p.open_shell()
        return p

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants