# WinRMの設定

## 概要

サーバーおよび環境の設定は、お客様の責任で行っていただく必要があります。参考およびテスト用途として、以下のPowerShellスクリプトを対象マシンで実行することで、自己署名証明書を使用したWinRMを有効化できます。本番環境では、公開認証局 (CA) によって発行された証明書を作成することを推奨します。

<pre class="language-powershell" data-overflow="wrap" data-line-numbers><code class="lang-powershell"><strong># WinRMを有効化
</strong>Set-NetConnectionProfile -NetworkCategory Private
winrm quickconfig -force
Enable-PSRemoting -force

# 非SSLトラフィックを許可（ポート5985）
winrm set winrm/config/service '@{AllowUnencrypted="true"}'
winrm set winrm/config/service/auth '@{Basic="true"}'
winrm set winrm/config/client/auth '@{Basic="true"}'

# SSL用の証明書を作成（ポート5986）
$Hostname = [System.Net.Dns]::GetHostByName($env:computerName).HostName
$Thumbprint = (New-SelfSignedCertificate -Subject "CN=$Hostname" -TextExtension '2.5.29.37={text}1.3.6.1.5.5.7.3.1').Thumbprint
$A = '@{Hostname="'+$Hostname+'"; CertificateThumbprint="'+$Thumbprint+'"}'
winrm create winrm/config/Listener?Address=*+Transport=HTTPS $A

# ファイアウォール規則
New-NetFirewallRule -DisplayName "WinRM" -Group "Windows Remote Management" -Program "System" `
  -Protocol TCP -LocalPort "5985" -Profile Domain,Private
New-NetFirewallRule -DisplayName "WinRM" -Group "Windows Remote Management" -Program "System" `
  -Protocol TCP -LocalPort "5985" -Profile Public
New-NetFirewallRule -DisplayName "WinRM Secure" -Group "Windows Remote Management" -Program "System" `
  -Protocol TCP -LocalPort "5986" -Profile Domain,Private
New-NetFirewallRule -DisplayName "WinRM Secure" -Group "Windows Remote Management" -Program "System" `
  -Protocol TCP -LocalPort "5986" -Profile Public
</code></pre>

以下は、このスクリプトがWindowsマシン上でWinRMを構成するために実行する処理の概要です。

1. ネットワーク接続プロファイルを「プライベート」に設定

```powershell
Set-NetConnectionProfile -NetworkCategory Private
```

2. WinRMを構成して有効化

```powershell
winrm quickconfig -force
Enable-PSRemoting -force
```

3. ポート5985での非SSL (暗号化なし) 通信を許可

```powershell
winrm set winrm/config/service '@{AllowUnencrypted="true"}'
winrm set winrm/config/service/auth '@{Basic="true"}'
winrm set winrm/config/client/auth '@{Basic="true"}'
```

4. ポート5986での暗号化通信 (HTTPS) 用に自己署名SSL証明書を作成

```powershell
$Hostname = [System.Net.Dns]::GetHostByName($env:computerName).HostName
$Thumbprint = (New-SelfSignedCertificate -Subject "CN=$Hostname" -TextExtension '2.5.29.37={text}1.3.6.1.5.5.7.3.1').Thumbprint
$A = '@{Hostname="'+$Hostname+'"; CertificateThumbprint="'+$Thumbprint+'"}'
winrm create winrm/config/Listener?Address=*+Transport=HTTPS $A
```

5. Windowsファイアウォールで受信通信を許可するルールを作成 (ポート5985: 非SSL、ポート5986: SSL)

```powershell
New-NetFirewallRule -DisplayName "WinRM" -Group "Windows Remote Management" -Program "System" `
  -Protocol TCP -LocalPort "5985" -Profile Domain,Private
New-NetFirewallRule -DisplayName "WinRM" -Group "Windows Remote Management" -Program "System" `
  -Protocol TCP -LocalPort "5985" -Profile Public
New-NetFirewallRule -DisplayName "WinRM Secure" -Group "Windows Remote Management" -Program "System" `
  -Protocol TCP -LocalPort "5986" -Profile Domain,Private
New-NetFirewallRule -DisplayName "WinRM Secure" -Group "Windows Remote Management" -Program "System" `
  -Protocol TCP -LocalPort "5986" -Profile Public
```

このスクリプトを実行すると、WinRMは非暗号化通信 (ポート5985) および暗号化通信 (ポート5986) の両方によるリモート接続を許可するよう構成されます。また、これらのポートへの受信通信を許可するWindowsファイアウォールルールも作成されます。

Windowsサーバーからは、PowerShellを使用して対象マシンへの接続をテストできます。

```
Test-NetConnection -ComputerName <host> -Port <port>
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.keeper.io/jp/keeperpam/privileged-access-manager/references/setting-up-winrm.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
