2017-04-21 22 views
0

私はwinhostを使用してCentOS上でPython 2.7.13経由でWindowsサーバー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 

ファイアウォールに例外が追加され、サービスがアップしていることを確認しました。 WinRMのため

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> 

クライアント設定:

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 
>>> 

は、私が失敗/成功したログオンの監査を有効にしかし、私はどちらのfaiも見ません私の接続しようとして成功したか、成功したのか。

教えてください。足りないものは教えてください。私はローカルユーザー経由で接続したい。

あなたの援助を感謝します。

答えて

0
  1. ネットワーク接続タイプが「プライベート」であることを確認します。「パブリック」の場合、winrmは設定されません。
  2. コマンドプロンプトを開きタイプ:

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

  3. オープンPowerShellとタイプ:

    enable-psremoting set-item WSMan:\localhost\Client\TrustedHosts *

  4. ( '*' すべてのホストのために、あなたがしたいホストを指定することができます)
  5. あなたのpythonスクリプトで:

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

関連する問題