Manage Windows Hosts from Linux


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 -i  powershell-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
    [root@Linux ~]# 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
     [10.239.56.110]: 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()