자바스크립트를 활성화 해주세요

p013 Remote Powershell 서버사이드 설정 정리

 ·  ☕ 2 min read

윈도우즈에서 윈도우즈로

윈도우즈에서 윈도우즈로 Remote Powershell 하려면, 서버사이드에는 다음과 같은 명령을 내리면 됩니다.

Enable-PSRemoting -Force

TAB으로 보완기능을 사용하면 다음과 같이 입력합니다.

enable-psr[TAB] -f[TAB]

Windows Server 2008 R2 이전에는 스크립팅환경이 OFF이기 때문에, 덧붙여서 Set-ExecutionPolicy RemoteSigned -Force을 해줘야 합니다.

리눅스에서 윈도우즈로

그런데 리눅스에서 윈도우즈로 Remote Powershell하려면, 추가로 BASIC 인증을 허가할 필요가 있습니다.

winrm get winrm/config/service 으로 현재의 설정을 확인할 수 있습니다.

PS C:\> winrm get winrm/config/service
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 = false
    Auth
        Basic = false
        Kerberos = true
        Negotiate = true
        Certificate = false
        CredSSP = false
        CbtHardeningLevel = Relaxed
    DefaultPorts
        HTTP = 5985
        HTTPS = 5986
    IPv4Filter = *
    IPv6Filter = *
    EnableCompatibilityHttpListener = false
    EnableCompatibilityHttpsListener = false
    CertificateThumbprint
    AllowRemoteAccess = true

Auth 설정을 보면 Basic = false 으로 되어 있는데, 이를 true 로 변경해야 합니다.

1
2
3
4
5
# BASIC 인증허거
winrm set winrm/config/service/auth '@{Basic="true"}'

# 비암호화문 허가
winrm set winrm/config/service '@{AllowUnencrypted="true"}'

실제로 설정해 보면 이런 느낌입니다.

PS C:\> winrm set winrm/config/service/auth '@{Basic="true"}'
Auth
    Basic = true
    Kerberos = true
    Negotiate = true
    Certificate = false
    CredSSP = false
    CbtHardeningLevel = Relaxed

PS C:\> 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에서 접속할 수 있습니다.

  • 출력에도 나온 것처럼 Linux에서는 DefaultPorts HTTP = 5985 로 접속할 수 있습니다.
  • 필요하다면 파이어월 해제도 해줍니다.
1
New-NetFirewallRule -DisplayName 'Open WINRM HTTP' -Profile 'Private' -Direction Inbound -Action Allow -Protocol TCP -LocalPort 5985

리눅스에서 윈도우즈 관리하려면 remote powershell 이외에도 pywinrm을 사용하는 방법이 있습니다.

pywinrm

설치는 다음고 같이 합니다.

yum install epel-release
yum install python-pip
pip install WinRM

사용법은 리모트 파워쉘과 비슷합니다. 어차피 xml로 RPC호출문을 전달하고 받을 뿐입니다.

1
2
3
session = winrm.Session(<host name>, auth=(<username>, <password>))
session.run_ps(<cmdlet command>)  # powershell command
session.run_cmd(<windows command>)  # windows command

기타

go언어 커뮤니티에서도 remote powershell을 할 수 있는 패키지가 준비되어 있습니다. Ruby, Perl등도 레퍼런스를 참고해주세요.

레퍼런스

공유하기

tkim
글쓴이
tkim
Software Engineer