woxio770 发表于 2018-6-16 10:42:53

Manage Windows Hosts from Linux-wu

  Using Powershell

[*]  Configurations on the Windows Host
  On the target with Windows system, configure the WinRM server to accept basic authentication and allow unencrypted traffic.
  To enable basic auth, on Windows in an administrative command prompt run:
  winrm set winrm/config/Service/Auth @{Basic="true"}
  To enable unencrypted communication over http on Windows in an administrative command prompt you must also run:
  winrm set winrm/config/Service @{AllowUnencrypted="true"}
  Note these commands are run in CMD, not PowerShell.
  Basic authentication with WinRM can only access local machine accounts so you will need to use a local account on your Windows machine that is part of the administrator group, in our test environment, you can use administrator.

[*]  Configurations on the Linux Host
  On the host with Linux System, install PowerShell and set the environment variable, then run PowerShell to connect target system.
  1. Install PowerShell
  Download the RPM installer, then run:
  rpm -ipowershell-xxx.rpm
  If the system asks for dependency packages, please use yum or apt-get to install them.
  2. Set the environment variable
  echo “export LD_LIBRARY_PATH=psl-omi-provider-path/src:psl-omi-provider-path/omi/Unix/output/lib:${LD_LIBRARY_PATH}” >> /etc/profile
  source /etc/profile
  3. Run PowerShell to connect to target system
  # powershell
  PowerShell
  Copyright (C) Microsoft Corporation. All rights reserved.
  PS /root> $IP="192.168.xx.xx"(这里是Windows Host的IP)
  PS /root> $cred=Get-Credential
  Windows PowerShell credential request
  Enter your credentials.
  User: administrator
  Password for user administrator: ******** (这里是交互式的,需要输入Windows Host上的用户名、密码)
  PS /root> Enter-PSSession -ComputerName $IP -Credential $cred -Authentication basic
  : PS C:\Users\Administrator\Documents> ipconfig
  Reference:
  https://github.com/PowerShell/PowerShell
  https://github.com/Microsoft/omi/blob/master/Unix/doc/setup-ntlm-omi.md
  Using SSH

[*]  Configurations on the Windows Host
  
  Install freeSSHd on windows Host, you can get it from http://www.freesshd.com/freeSSHd.exe

[*]  On Linux Host
  Just run "ssh administrator@Windows_Host", input password.
  Also you can use python lib paramiko.(待验证)
import paramiko  

  
ssh = paramiko.SSHClient()
  
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  
ssh.connect("SSH-server-IP",22,"username", "password")
  
stdin, stdout, stderr = ssh.exec_command("command")
  
print stdout.readlines()
  
ssh.close()
页: [1]
查看完整版本: Manage Windows Hosts from Linux-wu