首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用本地帐户连接python winrm

使用本地帐户连接python winrm
EN

Stack Overflow用户
提问于 2017-04-21 19:09:26
回答 1查看 4K关注 0票数 0

我正在尝试使用winrm通过CentOS上的python2.7.13连接到Windows 2012。服务器不是域的一部分。我创建了一个单独的本地管理员帐户来连接到它。

使用winrm configSDDL default提供该用户的所有访问权限。

将我的客户端机器添加到受信任的主机中。

代码语言:javascript
复制
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

在防火墙中添加了异常,并确保服务已启动。

代码语言:javascript
复制
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的客户端设置:

代码语言:javascript
复制
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正在运行:

代码语言:javascript
复制
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:~ # 

但仍然是:

代码语言:javascript
复制
>>> 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
>>> 

此外,我启用了对失败/成功登录的审核,但我看不到连接尝试失败或成功。

请告诉我少了什么?我想通过本地用户连接。

感谢你的帮助。

EN

回答 1

Stack Overflow用户

发布于 2017-08-18 10:34:13

  1. 如果网络连接类型是"public“winrm,请确保在目标windows机器中网络连接类型为”私有“。
  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'])
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43550273

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档