簡體   English   中英

python winrm使用本地帳戶連接

[英]python winrm connect using local account

我正在嘗試使用Winrm在CentOS上通過python 2.7.13連接到Windows Server 2012。 該服務器不屬於域。 我創建了一個單獨的本地管理員帳戶來連接它。

winrm configSDDL default使用winrm configSDDL default為該用戶提供所有訪問權限。

將我的客戶端計算機添加到受信任的主機。

PS C:\Windows\system32> Get-Item WSMan:\localhost\Client\TrustedHosts


   WSManConfig: Microsoft.WSMan.Management\WSMan::localhost\Client

Type            Name                           SourceOfValue   Value
----            ----                           -------------   -----
System.String   TrustedHosts                                   172.27.150.95

在防火牆中添加了例外,並確保服務已啟動。

PS C:\Windows\system32> netsh advfirewall firewall add rule name="WinRM-HTTP" dir=in localport=5985 protocol=TCP action=allow
Ok.

PS C:\Windows\system32> Get-Service -ComputerName abc -Name winrm | Select Status

                                                                                                                                                         Status
                                                                                                                                                         ------
                                                                                                                                                        Running


PS C:\Windows\system32>

winrm的客戶端設置:

PS C:\Windows\system32> winrm get winrm/config/client
Client
    NetworkDelayms = 5000
    URLPrefix = wsman
    AllowUnencrypted = true
    Auth
        Basic = true
        Digest = true
        Kerberos = true
        Negotiate = true
        Certificate = true
        CredSSP = false
    DefaultPorts
        HTTP = 5985
        HTTPS = 5986
    TrustedHosts = 172.27.150.95

Telnet正在工作:

xyz:~ # telnet 172.27.148.29 5985
Trying 172.27.148.29...
Connected to abc (172.27.148.29).
Escape character is '^]'.
^]
telnet> quit
Connection closed.
xyz:~ # 

但仍然:

>>> s = winrm.Session('abc', auth=('abc\script-runner', 'xxx'))                   
>>> r = s.run_cmd('ipconfig', ['/all'])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/site-packages/winrm/__init__.py", line 37, in run_cmd
    shell_id = self.protocol.open_shell()
  File "/usr/local/lib/python2.7/site-packages/winrm/protocol.py", line 132, in open_shell
    res = self.send_message(xmltodict.unparse(req))
  File "/usr/local/lib/python2.7/site-packages/winrm/protocol.py", line 207, in send_message
    return self.transport.send_message(message)
  File "/usr/local/lib/python2.7/site-packages/winrm/transport.py", line 190, in send_message
    raise InvalidCredentialsError("the specified credentials were rejected by the server")
winrm.exceptions.InvalidCredentialsError: the specified credentials were rejected by the server
>>> 

另外,我為失敗/成功的登錄啟用了審核功能,但是嘗試連接失敗或失敗。

請告訴我缺少了什么? 我想通過本地用戶連接。

感謝您的協助。

  1. 確保在目標Windows計算機中,網絡連接類型為“專用”,如果為“公共”,則不會配置winrm。
  2. 打開命令提示符並鍵入:

    winrm qc winrm set winrm/config/service @{AllowUnencrypted="true"}

  3. 打開Powershell並輸入:

    enable-psremoting set-item WSMan:\\localhost\\Client\\TrustedHosts * (“ *”適用於所有主機,您可以指定所需的主機)

  4. 在您的python腳本中:

    import winrm s = winrm.Session('yourWindowsHost', auth=('yourLocalUser', 'passwordInPlainText')) r = s.run_cmd('ipconfig', ['/all'])

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM