Recently encountered projects need to use Windows Server, previously deployed separately, first require Linux to connect windows, using WinRM to
One, configuring Windows WinRM
1. Run as follows, if not returned, the WinRM is not turned on
PS c:\users\administrator> WinRM Enumerate Winrm/config/listener
2. Configuring the WinRM base configuration
PS c:\users\administrator> WinRM Quickconfig has been running the WinRM service on this computer. WinRM has not been set up to manage this computer and allows remote access to it. The following changes must be made: Creating a WinRM listener on http://* accepts Ws-man requests for any IP on this machine. Configure Localaccounttokenfilterpolicy to remotely grant administrative rights to local users. Do you want to make these changes [y/n]? The YWINRM has been updated to be used for remote administration. Creating a WinRM listener on http://* accepts Ws-man requests for any IP on this machine. Configured Localaccounttokenfilterpolicy to remotely grant administrative rights to local users.
3. View the WinRM service listener for Windows
PS c:\users\administrator> winrm e winrm/config/listenerlistener Address = * Transport = HTTP Port = 5985 H Ostname Enabled = True URLPrefix = Wsman certificatethumbprint Listeningon = 127.0.0.1, 172.18.232.248,:: 1, F E80::5EFE:172.18.232.248%12, fe80::4963:ce66:e004:e54%17
4. Configuring the 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. Configure the WinRM service encryption method to allow non-encryption
ps c:\users\administrator> winrm set winrm/config/service ' @{AllowUnencrypted= ' True "} ' Service rootsddl = o:nsg:bad:p (A;; GA;;; BA) (A;; Gr;;;i U) 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
Second, the Linux connection
1.python feet
#!/usr/bin/pythonimport winrmwin2008 = 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. Running
# python winp.py volume in drive c has no label. volume serial number is 50e1-e273 directory of c:\users2018/07/10 10:10 <dir> . 2018/07/10 10:10 <dir> &NBSP;&NBSP, .... 2018/07/06 08:57 <dir> Administrator2009/07/14 12:57 <DIR> Public2018/07/11 18:21 <DIR> seedeer 0 file (s) 0 bytes 5 dir (s) 252,649,209,856 bytes free
Python winrm connection windows