---
title: "OpenSSH Windows Key Auth: Cài đặt chi tiết từ đầu và kiểm tra hoạt động thực tế"
description: "Hướng dẫn cài đặt OpenSSH Server trên Windows VPS, cấu hình xác thực SSH Key cho tài khoản Administrator và Standard User, kiểm tra log thực tế."
canonical: "https://thuecloud.vn/openssh-windows-key-auth-cai-dat-chi-tiet-tu-dau-va-kiem-tra-hoat-dong-thuc-te"
markdown_url: "https://thuecloud.vn/openssh-windows-key-auth-cai-dat-chi-tiet-tu-dau-va-kiem-tra-hoat-dong-thuc-te.md"
locale: "vi"
kind: "article"
published_at: "2026-11-22T16:18:27.719Z"
updated_at: "2026-11-22T16:18:25.613Z"
site: "ThueCloud.Vn"
estimated_tokens: 2188
---
# OpenSSH Windows Key Auth: Cài đặt chi tiết từ đầu và kiểm tra hoạt động thực tế

> Hướng dẫn cài đặt OpenSSH Server trên Windows VPS, cấu hình xác thực SSH Key cho tài khoản Administrator và Standard User, kiểm tra log thực tế.

- Canonical HTML: https://thuecloud.vn/openssh-windows-key-auth-cai-dat-chi-tiet-tu-dau-va-kiem-tra-hoat-dong-thuc-te
- Markdown URL: https://thuecloud.vn/openssh-windows-key-auth-cai-dat-chi-tiet-tu-dau-va-kiem-tra-hoat-dong-thuc-te.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

- Cài đặt OpenSSH Server và mở cổng Firewall trên Windows
- Cấu hình SSH Key Auth cho tài khoản Administrator
  - Tắt đăng nhập bằng mật khẩu (khuyên dùng sau khi test thành công)
- Kiểm tra hoạt động thực tế và đọc log xác thực
- Câu hỏi thường gặp (FAQ)
  - Tại sao tôi đã bỏ public key vào C:\Users\Administrator\.ssh\authorized_keys nhưng vẫn bị hỏi mật khẩu?
  - Làm sao để đổi shell mặc định khi SSH vào Windows từ cmd.exe sang PowerShell?
  - Nếu khóa mất quyền đăng nhập password trước khi test key thành công thì xử lý thế nào?

Quản trị [Cloud VPS Việt Nam](https://thuecloud.vn/vps-viet-nam) chạy Windows Server qua Remote Desktop (RDP) truyền thống không phải lúc nào cũng tiện lợi khi bạn cần tự động hóa deploy script hoặc truyền file qua `scp`/`rsync`. Cài đặt OpenSSH Server kết hợp xác thực SSH Key giúp bạn truy cập dòng lệnh an toàn mà không cần mở mật khẩu. Bài viết này hướng dẫn cài đặt từ đầu và xử lý điểm khác biệt quan trọng về phân quyền file key trên Windows.

> **Tóm tắt nhanh (TL;DR):**
> - Cài đặt tính năng `OpenSSH.Server` qua PowerShell với quyền Administrator và bật dịch vụ `sshd` tự khởi động.
> - Tài khoản thuộc nhóm **Administrators** bắt buộc lưu public key tại `C:\ProgramData\ssh\administrators_authorized_keys` (không phải trong `%USERPROFILE%\.ssh`).
> - Thiết lập quyền ACL chặt chẽ (`SYSTEM` và `Administrators` only) bằng `icacls`, nếu sai quyền OpenSSH sẽ từ chối xác thực key.
> - *Cập nhật: 11/2026*

## 1. Cài đặt OpenSSH Server và mở cổng Firewall trên Windows

Mở PowerShell với quyền **Run as Administrator** và kiểm tra trạng thái gói OpenSSH sẵn có:

```powershell
Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH*'

# Cài đặt OpenSSH Server
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0

# Khởi động và đặt tự chạy cùng Windows
Start-Service sshd
Set-Service -Name sshd -StartupType 'Automatic'
```

Kiểm tra rule tường lửa mặc định cho cổng 22 (hoặc tạo mới nếu chưa có):

```powershell
if (!(Get-NetFirewallRule -Name "OpenSSH-Server-In-TCP" -ErrorAction SilentlyContinue)) {
    New-NetFirewallRule -Name 'OpenSSH-Server-In-TCP' -DisplayName 'OpenSSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22
}
```

## 2. Cấu hình SSH Key Auth cho tài khoản Administrator

Đây là bước nhiều quản trị viên hay gặp lỗi nhất vì khác với Linux. Trên Windows, cấu hình mặc định trong `C:\ProgramData\ssh\sshd_config` có đoạn:

```text
Match Group administrators
       AuthorizedKeysFile __PROGRAMDATA__/ssh/administrators_authorized_keys
```

Do đó, với tài khoản Administrator, bạn phải ghi public key (`id_ed25519.pub` từ máy cá nhân) vào file `C:\ProgramData\ssh\administrators_authorized_keys` và thiết lập ACL chính xác bằng `icacls`:

```powershell
$authFile = "C:\ProgramData\ssh\administrators_authorized_keys"
Add-Content -Force -Path $authFile -Value "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI... admin@laptop"

# Xóa quyền kế thừa và chỉ cấp quyền cho SYSTEM + Administrators
icacls.exe $authFile /inheritance:r /grant "Administrators:F" /grant "SYSTEM:F"
```

| Loại tài khoản Windows | Đường dẫn lưu Public Key | Yêu cầu phân quyền ACL |
| :--- | :--- | :--- |
| **Standard User** | `C:\Users\<user>\.ssh\authorized_keys` | Chỉ `SYSTEM`, `Administrators` và `<user>` có quyền đọc/ghi |
| **Administrators Group** | `C:\ProgramData\ssh\administrators_authorized_keys` | Bắt buộc tắt inheritance, chỉ cấp cho `Administrators` và `SYSTEM` |

### Tắt đăng nhập bằng mật khẩu (khuyên dùng sau khi test thành công)

Chỉnh sửa `C:\ProgramData\ssh\sshd_config`:

```text
PubkeyAuthentication yes
PasswordAuthentication no
```

Sau đó khởi động lại dịch vụ: `Restart-Service sshd`.

## 3. Kiểm tra hoạt động thực tế và đọc log xác thực

Từ máy trạm Linux/macOS, thử kết nối kèm cờ `-v` để quan sát quá trình trao đổi key:

```bash
ssh -i ~/.ssh/id_ed25519 -v Administrator@<IP_VPS_WINDOWS>
```

Nếu thành công, bạn sẽ thấy dòng `Authentication succeeded (publickey)`. Trong trường hợp cần tự động hóa các tác vụ AI hoặc workflow từ xa trên Windows VPS, bạn có thể kết hợp với [Temporal Python Worker](https://thuecloud.vn/temporal-python-worker-kinh-nghiem-van-hanh-thuc-te-va-so-sanh-phuong-an-thay-the) hoặc triển khai [FastAPI RAG với Gemini trên VPS](https://thuecloud.vn/huong-dan-ket-hop-gemini-4-neon-voi-fastapi-rag-xay-dung-tinh-nang-ai-thuc-te-tren-vps). Xem thêm giải đáp về cổng kết nối tại trang [Hỏi đáp (FAQ)](https://thuecloud.vn/faq).

> **Trải nghiệm Windows VPS tốc độ cao tại ThueCloud.Vn:**
> Hạ tầng **KVM Enterprise NVMe tại `vn-hn`** hỗ trợ Windows Server bản quyền dùng thử/OEM, **SLA 99,9%**, **VAT 0%**, **hoàn tiền 07 ngày**:
> - **VPS VN 2** (2 vCPU, 2GB RAM, 35GB NVMe): **78.000đ/tháng** (năm) hoặc **90.000đ/tháng**.
> - **VPS VN 3** (4 vCPU, 4GB RAM, 60GB NVMe): **139.000đ/tháng** (năm) hoặc **170.000đ/tháng** — mượt mà cho Windows Server + OpenSSH/RDP. Tham khảo ngay tại [Bảng giá VPS](https://thuecloud.vn/pricing).

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

### Tại sao tôi đã bỏ public key vào `C:\Users\Administrator\.ssh\authorized_keys` nhưng vẫn bị hỏi mật khẩu?
Vì mặc định `sshd_config` trên Windows có block `Match Group administrators` chuyển hướng file xác thực sang `C:\ProgramData\ssh\administrators_authorized_keys`. Bạn phải đặt key vào đúng file này và chạy `icacls` chuẩn xác.

### Làm sao để đổi shell mặc định khi SSH vào Windows từ `cmd.exe` sang `PowerShell`?
Chạy lệnh sau trên PowerShell với quyền Admin để đặt PowerShell 7 hoặc Windows PowerShell làm shell mặc định cho OpenSSH:
`New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" -Name DefaultShell -Value "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -PropertyType String -Force`.

### Nếu khóa mất quyền đăng nhập password trước khi test key thành công thì xử lý thế nào?
Bạn vẫn có thể đăng nhập vào Windows VPS thông qua giao diện **RDP** hoặc **VNC Console** trong trang quản trị của ThueCloud để sửa lại file `sshd_config`.

## References / Sources

- https://learn.microsoft.com/en-us/windows-server/administration/openssh/openssh_install_firstuse
- https://learn.microsoft.com/en-us/windows-server/administration/openssh/openssh_keymanagement

---

## 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)
