# ============================================================ # SSH 金鑰設定腳本 — 讓 SCP 上傳不需要輸入密碼 # 只需要執行一次! # ============================================================ # ─── 請修改以下設定 ────────────────────────────────────────── $NAS_IP = "192.168.1.100" # ← 改成你的 NAS IP $NAS_USER = "admin" # ← 改成你的 NAS 帳號 # ───────────────────────────────────────────────────────────── Write-Host "=== 設定 SSH 免密碼登入 ===" -ForegroundColor Cyan # 1. 產生 SSH 金鑰(如果已有就跳過) $keyPath = "$env:USERPROFILE\.ssh\id_rsa" if (-not (Test-Path $keyPath)) { Write-Host "產生 SSH 金鑰..." -ForegroundColor Yellow ssh-keygen -t rsa -b 4096 -f $keyPath -N "" Write-Host "✅ 金鑰已產生" -ForegroundColor Green } else { Write-Host "✅ SSH 金鑰已存在,跳過" -ForegroundColor Green } # 2. 把公鑰複製到 NAS(需要輸入一次 NAS 密碼) Write-Host "" Write-Host "請輸入你的 NAS 密碼(只需這一次):" -ForegroundColor Yellow $pubKey = Get-Content "$keyPath.pub" # 用 ssh 把公鑰附加到 NAS 的 authorized_keys $cmd = "mkdir -p ~/.ssh && chmod 700 ~/.ssh && echo '$pubKey' >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys" ssh "${NAS_USER}@${NAS_IP}" $cmd Write-Host "" Write-Host "✅ 完成!之後 SCP 上傳不需要再輸入密碼了。" -ForegroundColor Green Write-Host "" Write-Host "現在可以測試執行 auto_update.ps1" -ForegroundColor Cyan