发布时间:2019-09-19 08:02:35编辑:auto阅读(1474)
最近遇到项目需要使用windows 服务器,之前分开部署,先需求linux连接windows,使用winrm即可
一、配置windows winrm
1.运行如下,如果没有返回,则没有开启winrm
PS C:\Users\Administrator> winrm enumerate winrm/config/listener
2.配置winrm基础配置
PS C:\Users\Administrator> winrm quickconfig 已在此计算机上运行 WinRM 服务。 WinRM 没有设置成为了管理此计算机而允许对其进行远程访问。 必须进行以下更改: 在 HTTP://* 上创建 WinRM 侦听程序接受 WS-Man 对此机器上任意 IP 的请求。 配置 LocalAccountTokenFilterPolicy 以远程向本地用户授予管理权限。 执行这些更改吗[y/n]? y WinRM 已经进行了更新,以用于远程管理。 在 HTTP://* 上创建 WinRM 侦听程序接受 WS-Man 对此机器上任意 IP 的请求。 已配置 LocalAccountTokenFilterPolicy 以远程向本地用户授予管理权限。
3. 查看windows的winrm service listener
PS C:\Users\Administrator> winrm e winrm/config/listener Listener Address = * Transport = HTTP Port = 5985 Hostname Enabled = true URLPrefix = wsman CertificateThumbprint ListeningOn = 127.0.0.1, 172.18.232.248, ::1, fe80::5efe:172.18.232.248%12, fe80::4963:ce66:e004:e54%17
4.配置winrm auth
PS C:\Users\Administrator> winrm set winrm/config/service/auth '@{Basic="true"}' Auth Basic = true Kerberos = true Negotiate = true Certificate = false CredSSP = false CbtHardeningLevel = Relaxed
5.配置winrm service 加密方式为允许非加密
PS C:\Users\Administrator> winrm set winrm/config/service '@{AllowUnencrypted="true"}' Service RootSDDL = O:NSG:BAD:P(A;;GA;;;BA)(A;;GR;;;IU)S:P(AU;FA;GA;;;WD)(AU;SA;GXGW;;;WD) MaxConcurrentOperations = 4294967295 MaxConcurrentOperationsPerUser = 1500 EnumerationTimeoutms = 240000 MaxConnections = 300 MaxPacketRetrievalTimeSeconds = 120 AllowUnencrypted = true Auth Basic = true Kerberos = true Negotiate = true Certificate = false CredSSP = false CbtHardeningLevel = Relaxed DefaultPorts HTTP = 5985 HTTPS = 5986 IPv4Filter = * IPv6Filter = * EnableCompatibilityHttpListener = false EnableCompatibilityHttpsListener = false CertificateThumbprint AllowRemoteAccess = true
二、在linux连接
1.python 脚
#!/usr/bin/python import winrm win2008 = winrm.Session('http://11.22.33.44:5985/wsman',auth=('administrator','xxxx')) r = win2008.run_cmd('cd .. & dir') print r.std_out.decode() print r.std_err
2.运行
# python winP.py Volume in drive C has no label. Volume Serial Number is 50E1-E273 Directory of C:\Users 2018/07/10 10:10 <DIR> . 2018/07/10 10:10 <DIR> .. 2018/07/06 08:57 <DIR> Administrator 2009/07/14 12:57 <DIR> Public 2018/07/11 18:21 <DIR> seedeer 0 File(s) 0 bytes 5 Dir(s) 252,649,209,856 bytes free
上一篇: python pip 修改源
下一篇: python 操作redis集群
47839
46385
37278
34728
29311
25969
24907
19947
19540
18019
5789°
6410°
5925°
5959°
7062°
5909°
5941°
6436°
6403°
7774°