2.0 KiB
2.0 KiB
Hướng dẫn mở SSH trên VPS (1 lần duy nhất)
Cách dễ nhất — copy script vào RDP
-
RDP vào VPS:
- Windows + R →
mstsc - Computer:
103.124.94.58:3389 - User:
Administrator - Password: (dùng password đã cung cấp)
- Windows + R →
-
Mở PowerShell AS ADMINISTRATOR:
- Start → gõ "PowerShell" → right-click → Run as Administrator
-
Copy-paste toàn bộ file
scripts/deployment/00-enable-ssh-server.ps1vào PowerShell → Enter. -
Đợi ~1 phút, khi thấy
DONE — SSH server readylà xong. -
Báo lại cho dev, dev sẽ test connection:
ssh -i ~/.ssh/dyd_vps Administrator@103.124.94.58 hostname
Nếu copy-paste qua RDP clipboard không được
Option A — Upload file qua RDP mapped drive:
- Trong mstsc → More → Local Resources → Drives → check
D:\(hoặc drive chứa repo) - Sau khi RDP, mở File Explorer →
\\tsclient\D\...\scripts\deployment\00-enable-ssh-server.ps1 - Right-click file → Run with PowerShell (As Admin)
Option B — Tải từ Gitea/GitHub (sau khi push):
Invoke-WebRequest -Uri '<raw-url>/scripts/deployment/00-enable-ssh-server.ps1' -OutFile C:\Temp\00-enable-ssh.ps1
powershell -ExecutionPolicy Bypass -File C:\Temp\00-enable-ssh.ps1
Script làm gì?
- Install OpenSSH Server capability (Windows feature)
- Start
sshdservice + set auto-start - Open firewall port 22
- Set default SSH shell = PowerShell (chứ không phải cmd)
- Add public key
dyd-vps-deploy-20260415vàoadministrators_authorized_keys - Fix file permission (chỉ Admin + SYSTEM được đọc)
Idempotent — chạy nhiều lần OK, không side effect.
Security
- Public key đã embed trong script
- Private key nằm trên máy dev (
~/.ssh/dyd_vps) — KHÔNG rời máy - Nếu mất private key → chạy lại script sau khi đổi
$PublicKeyvới key mới - Disable SSH sau khi xong deploy:
Stop-Service sshd; Set-Service sshd -StartupType Disabled