我試圖通過使用winrm的CentOS上的python 2.7.13連接到Windows server 2012。服務器不是域的一部分。我創建了一個單獨的本地管理員帳戶來連接它。使用本地帳戶連接python winrm
使用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
>>>
而且,我啓用審計失敗/成功登錄但我沒有看到任何輝帶領或成功爲我的連接嘗試。
請告訴我缺少什麼?我想通過本地用戶連接。
感謝您的協助。