---
title: "Cấu hình WinRM qua HTTPS và OpenSSH Remoting điều khiển Windows VPS từ GitHub Actions"
description: "Hướng dẫn winrm https openssh windows vps bảo mật cổng 5986 và SSH Key Ed25519 giúp GitHub Actions tự động deploy code, khởi động lại IIS an toàn."
canonical: "https://thuecloud.vn/quan-tri-windows-vps-tu-xa-qua-winrm-https-va-openssh-remoting-tu-ci-cd"
markdown_url: "https://thuecloud.vn/quan-tri-windows-vps-tu-xa-qua-winrm-https-va-openssh-remoting-tu-ci-cd.md"
locale: "vi"
kind: "article"
published_at: "2026-11-22T16:18:06.106Z"
updated_at: "2026-11-22T16:18:01.848Z"
site: "ThueCloud.Vn"
estimated_tokens: 3388
---
# Cấu hình WinRM qua HTTPS và OpenSSH Remoting điều khiển Windows VPS từ GitHub Actions

> Hướng dẫn winrm https openssh windows vps bảo mật cổng 5986 và SSH Key Ed25519 giúp GitHub Actions tự động deploy code, khởi động lại IIS an toàn.

- Canonical HTML: https://thuecloud.vn/quan-tri-windows-vps-tu-xa-qua-winrm-https-va-openssh-remoting-tu-ci-cd
- Markdown URL: https://thuecloud.vn/quan-tri-windows-vps-tu-xa-qua-winrm-https-va-openssh-remoting-tu-ci-cd.md
- Organization: ThueCloud.Vn
- Support Email: support@thuecloud.vn
- Hotline: 03333 499 48
- Published: 2026-11-22
- Updated: 2026-11-22

## Mục lục

- So sánh WinRM HTTPS (5986) và OpenSSH PowerShell Remoting (22)
- Thiết lập WinRM HTTPS (5986) và OpenSSH Server trên Windows VPS
- Tích hợp GitHub Actions tự động deploy .NET API lên IIS hoặc Server Core
- Tài liệu liên quan & Giải pháp ThueCloud
- Câu hỏi thường gặp (FAQ)
  - Vì sao GitHub Actions chạy SSH vào Windows VPS báo lỗi Permission denied dù đã thêm public key?
  - Có nên mở port WinRM 5986 hoặc SSH 22 ra toàn bộ Internet không?
  - Dùng OpenSSH Remoting có gọi được trực tiếp lệnh PowerShell thay vì CMD không?
  - WinRM HTTPS dùng chứng chỉ tự ký (Self-Signed) có an toàn cho script nội bộ không?

Để điều khiển **Windows VPS** tự động từ GitHub Actions mà không mở RDP công khai, kỹ sư hệ thống nên cấu hình **WinRM qua HTTPS** (port `5986/TCP`) hoặc **OpenSSH Remoting** (port `22/TCP`) dùng khóa Ed25519. Hai giao thức này mã hóa toàn bộ phiên PowerShell từ xa, loại bỏ nguy cơ rò rỉ thông tin đăng nhập qua mạng.

> **Tóm tắt nhanh (TL;DR):**
> - **Ngừng dùng WinRM HTTP mặc định:** Port `5985/TCP` truyền tải không mã hóa TLS nếu bật Basic Auth; luôn chuyển sang port `5986/TCP` gắn chứng chỉ TLS hợp lệ.
> - **Ưu tiên OpenSSH Remoting cho CI/CD:** Xác thực bằng cặp khóa `Ed25519`, tương thích trực tiếp với runner Linux trên GitHub Actions mà không cần cài thêm thư viện WinRM phía client.
> - **Giới hạn bề mặt mạng:** Chỉ cho phép IP VPN nội bộ hoặc IP runner hợp lệ truy cập port `5986` và `22` trên Windows Defender Firewall.
> - **Hạ tầng triển khai:** Vận hành mượt trên các gói [VPS Việt Nam](https://thuecloud.vn/vps-viet-nam) KVM NVMe hoặc hệ thống tách lớp của nhóm [giải pháp doanh nghiệp](https://thuecloud.vn/giai-phap) đặt tại Hà Nội (`vn-hn`).
> - *Cập nhật: 11/2026*

## So sánh WinRM HTTPS (5986) và OpenSSH PowerShell Remoting (22)

Trên Windows Server 2022 và 2025, PowerShell hỗ trợ hai kênh điều khiển từ xa phổ biến là WS-Management (WinRM) và SSH Remoting. Việc chọn giao thức nào phụ thuộc vào công cụ CI/CD đang dùng (Ansible, Terraform hay GitHub Actions) và chính sách xác thực của doanh nghiệp. Trước khi mở các kênh quản trị, bạn nên tham khảo thêm bài [sử dụng PowerShell quản trị VPS Windows nhanh hơn giao diện GUI](https://thuecloud.vn/su-dung-powershell-quan-tri-vps-windows-nhanh-hon-giao-dien-gui) và tinh gọn dịch vụ nền theo hướng dẫn [tối ưu Windows Server 2022/2025 giảm RAM xuống dưới 1GB](https://thuecloud.vn/toi-uu-windows-server-2022-2025-tat-dich-vu-thua-giam-ram-xuong-duoi-1gb).

| Tiêu chí so sánh | WinRM HTTP (Port 5985) | WinRM HTTPS (Port 5986) | OpenSSH Remoting (Port 22) |
| --- | --- | --- | --- |
| **Mã hóa đường truyền** | Yếu/Không có TLS (dễ bị nghe lén nếu dùng Basic) | TLS 1.2 / 1.3 đầy đủ qua chứng chỉ X.509 | SSHv2 tiêu chuẩn (AES-GCM / ChaCha20) |
| **Cơ chế xác thực** | NTLM / Kerberos / Basic | Chứng chỉ Client, NTLM, hoặc Basic qua TLS | SSH Public Key (`Ed25519` / `RSA`) |
| **Tương thích runner Linux (GitHub Actions)** | Cần plugin Python (`pywinrm`) | Cần `pywinrm` / Ansible WinRM | Gốc Linux có sẵn `ssh`, `scp`, `rsync` |
| **Truyền tải tệp build (.zip/.dll)** | Tương đối chậm qua SOAP/WSMan | Chậm hơn SCP/SFTP với tệp lớn | Nhanh trực tiếp qua **SFTP / SCP** |
| **Mức độ khuyến nghị Production** | **Không khuyến nghị** | Tốt (cho hệ sinh thái Microsoft / Ansible) | **Rất cao** (cho GitHub Actions / GitLab CI) |

## Thiết lập WinRM HTTPS (5986) và OpenSSH Server trên Windows VPS

Nếu hệ thống dùng Ansible hoặc PowerShell nội bộ, bạn cần tạo chứng chỉ số khớp với `Hostname` hoặc IP của VPS, gán cho listener HTTPS của WinRM và xóa listener HTTP `5985` dư thừa. Song song đó, bật OpenSSH Server bản gốc của Windows giúp việc deploy ứng dụng web sau bước [cài đặt IIS Web Server và ASP.NET Core Hosting Bundle trên Windows VPS](https://thuecloud.vn/cai-dat-iis-web-server-va-asp-net-core-hosting-bundle-tren-windows-vps) trở nên gọn gàng hơn nhiều.

```powershell
# === PHẦN 1: Cấu hình WinRM over HTTPS (Port 5986) ===
$dnsName = "<DOMAIN_OR_VPS_IP>"
$cert = New-SelfSignedCertificate -DnsName $dnsName -CertStoreLocation "Cert:\LocalMachine\My"

# Xóa listener HTTP cũ (nếu có) và tạo listener HTTPS gắn Thumbprint chứng chỉ
Get-ChildItem WSMan:\localhost\Listener | Where-Object { $_.Keys -match "Transport=HTTP" } | Remove-Item -Recurse -Force
New-Item -Path WSMan:\localhost\Listener -Transport HTTPS -Address * -CertificateThumbPrint $cert.Thumbprint -Force

# Tắt xác thực Unencrypted
Set-Item -Path WSMan:\localhost\Service\AllowUnencrypted -Value $false

# Mở port 5986 chỉ cho dải IP quản trị tin cậy
New-NetFirewallRule -DisplayName "WinRM HTTPS Trusted" -Direction Inbound -Protocol TCP -LocalPort 5986 -RemoteAddress "<TRUSTED_ADMIN_IP>" -Action Allow

# === PHẦN 2: Cài OpenSSH Server và cấu hình SSH Key cho tài khoản Admin ===
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
Start-Service sshd
Set-Service -Name sshd -StartupType Automatic

# Đặt PowerShell làm shell mặc định khi SSH vào Windows
New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" -Name DefaultShell -Value "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -PropertyType String -Force
```

Lưu ý quan trọng khi cấu hình SSH Key cho tài khoản thuộc nhóm `Administrators` trên Windows: OpenSSH Server trên Windows đọc khóa công khai từ tệp `C:\ProgramData\ssh\administrators_authorized_keys` (thay vì `~/.ssh/authorized_keys`), và tệp này chỉ được phép cấp quyền cho `SYSTEM` và nhóm `Administrators`.

## Tích hợp GitHub Actions tự động deploy .NET API lên IIS hoặc Server Core

Sau khi thiết lập SSH Key và lưu khóa bí mật vào GitHub Secrets (`VPS_SSH_KEY`), quy trình CI/CD có thể nén artifact, truyền qua SCP và thực thi lệnh dừng/bật AppPool IIS hoặc dịch vụ Kestrel từ xa. Mô hình này kết hợp cực kỳ hiệu quả khi bạn [triển khai .NET 8/9 Kestrel sau IIS](https://thuecloud.vn/trien-khai-net-8-9-kestrel-sau-iis-che-do-in-process-va-out-of-process) hoặc vận hành trên môi trường tinh gọn [chạy Windows Server Core 2025 không GUI cho API .NET](https://thuecloud.vn/chay-windows-server-core-2025-khong-gui-cho-api-net-giam-50-ram-va-patch).

```yaml
name: Deploy API to Windows VPS
on:
  push:
    branches: [ main ]

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Setup .NET 9
        uses: actions/setup-dotnet@v4
        with:
          dotnet-version: '9.0.x'

      - name: Publish Release
        run: dotnet publish ./src/Api/Api.csproj -c Release -o ./publish

      - name: Upload and Restart IIS AppPool via OpenSSH
        env:
          SSH_KEY: ${{ secrets.VPS_SSH_KEY }}
          VPS_HOST: ${{ secrets.VPS_HOST }}
          VPS_USER: ${{ secrets.VPS_USER }}
        run: |
          mkdir -p ~/.ssh
          echo "$SSH_KEY" > ~/.ssh/id_ed25519
          chmod 600 ~/.ssh/id_ed25519
          scp -o StrictHostKeyChecking=accept-new -r ./publish/* "${VPS_USER}@${VPS_HOST}:C:/Apps/ApiStaging/"
          ssh -o StrictHostKeyChecking=accept-new "${VPS_USER}@${VPS_HOST}" "Import-Module WebAdministration; Stop-WebAppPool -Name 'MyApiPool'; Copy-Item 'C:\Apps\ApiStaging\*' 'C:\Apps\ApiProd\' -Recurse -Force; Start-WebAppPool -Name 'MyApiPool'"
```

Khi mở đường kết nối quản trị từ xa, bạn cũng nên thực hiện [hardening Windows VPS bật SMBv3 Signing và tắt LLMNR, NetBIOS, NTLMv1](https://thuecloud.vn/hardening-windows-vps-bat-smbv3-signing-va-tat-llmnr-netbios-ntlmv1) để khóa các giao thức cũ dễ bị tấn công chuyển tiếp xác thực. Ngoài ra, nếu pipeline CI/CD hoặc worker trên Windows có gọi các API đối tác qua proxy với yêu cầu tương thích giao thức cao, bạn có thể tham khảo thêm kỹ thuật [chuẩn hóa HTTP/2 SETTINGS frame và ALPN khi gọi API qua proxy](https://thuecloud.vn/chuan-hoa-http2-settings-frame-va-alpn-khi-goi-api-qua-proxy) để tránh lỗi nghẽn kết nối từ phía WAF đích.

## Tài liệu liên quan & Giải pháp ThueCloud

Để mở rộng kiến thức chuyên sâu cùng chủ đề, bạn có thể tham khảo thêm:

- [Cài đặt và cấu hình GitHub Actions Self-Hosted Runner trên Windows Server 2022 VPS](https://thuecloud.vn/cai-dat-va-cau-hinh-github-actions-self-hosted-runner-tren-windows-server-2022-vps)
- [Quản trị cPanel WHM: Hướng dẫn cấu hình sao lưu từ xa qua FTP/S3 và kiểm tra khôi phục](https://thuecloud.vn/quan-tri-cpanel-whm-huong-dan-cau-hinh-sao-luu-tu-xa-qua-ftp-s3-va-kiem-tra-khoi-phuc)

Khám phá thêm hệ sinh thái tài nguyên và công cụ hỗ trợ tại ThueCloud: [Câu hỏi thường gặp (FAQ)](https://thuecloud.vn/faq), [ThueCloud Tools](https://thuecloud.vn/tools), [Bảng giá VPS & Proxy](https://thuecloud.vn/pricing).

> **Triển khai hạ tầng thực tế tại ThueCloud:** Khởi tạo ngay [VPS Việt Nam NVMe](https://thuecloud.vn/vps-viet-nam) với **VPS VN 1** chỉ từ `45.000đ/tháng đầu` hoặc **VPS VN 2** `78.000đ/tháng đầu` (KVM, 100% Enterprise NVMe, VAT 0%, SLA `99,9%`, hoàn tiền `07 ngày`) — xem chi tiết tại [bảng giá ThueCloud](https://thuecloud.vn/pricing).

## Câu hỏi thường gặp (FAQ)

### Vì sao GitHub Actions chạy SSH vào Windows VPS báo lỗi Permission denied dù đã thêm public key?
Nguyên nhân phổ biến nhất là bạn đặt khóa vào `C:\Users\<User>\.ssh\authorized_keys` đối với tài khoản thuộc nhóm `Administrators`. Trên Windows OpenSSH, tài khoản quản trị bắt buộc dùng tệp `C:\ProgramData\ssh\administrators_authorized_keys` với ACL chỉ cho phép `SYSTEM` và `Administrators`.

### Có nên mở port WinRM 5986 hoặc SSH 22 ra toàn bộ Internet không?
Không. Dù cả hai đều mã hóa đường truyền, việc mở công khai sẽ hứng chịu hàng nghìn lượt dò quét mật khẩu mỗi giờ. Hãy dùng Tailscale/WireGuard VPN hoặc giới hạn dải IP nguồn hợp lệ trên Windows Defender Firewall, và tắt xác thực mật khẩu (`PasswordAuthentication no`) trên OpenSSH.

### Dùng OpenSSH Remoting có gọi được trực tiếp lệnh PowerShell thay vì CMD không?
Có. Chỉ cần đặt giá trị Registry `DefaultShell` trong `HKLM:\SOFTWARE\OpenSSH` trỏ về `powershell.exe` (hoặc `pwsh.exe` nếu dùng PowerShell 7), mọi lệnh gửi từ GitHub Actions qua `ssh user@host "..."` sẽ thực thi trực tiếp trong môi trường PowerShell.

### WinRM HTTPS dùng chứng chỉ tự ký (Self-Signed) có an toàn cho script nội bộ không?
Chứng chỉ tự ký vẫn mã hóa toàn bộ phiên làm việc TLS giữa client và Windows VPS. Tuy nhiên, máy client cần tin cậy (trust) chứng chỉ gốc hoặc chủ động ghim (pin) đúng `Thumbprint` của chứng chỉ để phòng chống tấn công xen giữa (MITM).

## References / Sources

- https://learn.microsoft.com/en-us/windows/win32/winrm/installation-and-configuration-for-windows-remote-management
- https://learn.microsoft.com/en-us/powershell/scripting/security/remoting/ssh-remoting-in-powershell
- https://man7.org/linux/man-pages/

---

## Navigation & Machine-Readable Endpoints

- [Site Summary (llms.txt)](https://thuecloud.vn/llms.txt)
- [Full Technical Reference (llms-full.txt)](https://thuecloud.vn/llms-full.txt)
- [Pricing Catalog (Markdown)](https://thuecloud.vn/pricing.md)
- [Blog & Technical Guides (Markdown)](https://thuecloud.vn/blog.md)
- [XML Sitemap](https://thuecloud.vn/sitemap.xml)
