新增 user 帳號與 OpenSSH Server 自動部署;Telegram 步驟加 log 以便排查無聲失敗
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
45
DEPLOY.md
45
DEPLOY.md
@@ -116,16 +116,51 @@ cat /Volumes/Ventoy/ventoy/ventoy.json
|
||||
| 1 | `powershell -File C:\Scripts\Setup.ps1` | 看腳本內容 |
|
||||
| 2 | `net accounts /maxpwage:unlimited`(密碼永不過期) | 否 |
|
||||
| 3 | `Rename-Computer` 把主機名改成 `PC-XXXXX`(重開後生效) | 否 |
|
||||
| 4 | 下載 `https://telegram.org/dl/desktop/win64` → 靜默安裝(`/VERYSILENT /SUPPRESSMSGBOXES /NORESTART`) | **是** |
|
||||
| 5 | `shutdown /r /t 5` 重開機 | 否 |
|
||||
| 4 | `net user user 1234 /add`+`/logonpasswordchg:yes`(建立一般使用者 `user`,首次登入強制改密) | 否 |
|
||||
| 5 | 等網路→`Add-WindowsCapability OpenSSH.Server`+`Set-Service sshd Automatic`+`Start-Service sshd`(log: `firstlogon-sshd.log`) | **是** |
|
||||
| 6 | 等網路→下載 `https://telegram.org/dl/desktop/win64` → 靜默安裝(`/VERYSILENT /SUPPRESSMSGBOXES /NORESTART`,log: `firstlogon-telegram.log`) | **是** |
|
||||
| 7 | `shutdown /r /t 5` 重開機 | 否 |
|
||||
|
||||
Telegram 這條的注意事項:
|
||||
### 新加入的 `user` 帳號
|
||||
|
||||
- **要有網路**:OOBE 裡 `SkipMachineOOBE=true` 跳過了網路設定精靈,所以目標機必須有 Ethernet+DHCP,或本身已記住 Wi-Fi。網路不通時 `Invoke-WebRequest` 會失敗,但不會擋到 Order 5 的 reboot,只會讓 Telegram 沒裝成。
|
||||
- **per-user 安裝**:Telegram 安裝程式預設裝到 Admin 這個帳號底下,其他帳號看不到。要全機安裝就在 `ArgumentList` 加 `'/ALLUSERS'`。
|
||||
- **用途**:給使用者日常使用,和部署用的管理員 `Admin` 分開。
|
||||
- **權限**:一般 `Users` 群組(非 Administrators)。需要管理員權限時走 UAC。
|
||||
- **首次登入強制改密**:`/logonpasswordchg:yes` 會在下次登入時跳「密碼必須變更」。可以改成複雜密碼。
|
||||
- **如果 `net user` 因為 Windows 密碼政策拒絕 `1234`**:整條 Order 4 會失敗但不會擋後面,手動於 PowerShell 以 `New-LocalUser`+更寬的密碼重跑。
|
||||
|
||||
### OpenSSH Server(Order 5)
|
||||
|
||||
- 走 Windows 內建 Feature on Demand,**會從 Windows Update 下載** `OpenSSH.Server~~~~0.0.1.0`。需要外網。
|
||||
- 完成後 `sshd` 服務設成 `Automatic`(每次開機自動啟動),防火牆規則由 FoD 自動建立(TCP 22 inbound allow)。
|
||||
- 驗證:`Get-Service sshd` 應該 `Running`;`Get-NetFirewallRule -Name OpenSSH-Server-In-TCP` 應該 `Enabled=True`。
|
||||
- 用來遠端登入:`ssh Admin@<機器 IP>` 或 `ssh user@<機器 IP>`。初次使用要先在 `%ProgramData%\ssh\administrators_authorized_keys` 加公鑰(Windows OpenSSH 對 Administrators 群組的授權金鑰路徑特殊,不走 `~/.ssh/authorized_keys`)。
|
||||
|
||||
### Telegram(Order 6)的注意事項
|
||||
|
||||
- **要有網路**:OOBE 裡 `SkipMachineOOBE=true` 跳過了網路設定精靈,所以目標機必須有 Ethernet+DHCP,或本身已記住 Wi-Fi。這次有 log 可以驗證—`C:\Windows\Temp\firstlogon-telegram.log` 會寫 `NetWait=?s`、`Downloaded ?B`、`Exit ?`。
|
||||
- **網路等待上限 60 秒**:Order 5 和 Order 6 都各跑一次 `Test-Connection 8.8.8.8` 迴圈,最多等 30 回合×2 秒;ICMP 被擋住的環境會等完整 60 秒但 HTTPS 其實可用,也能跑下去。
|
||||
- **per-user 安裝**:Telegram 安裝程式預設裝到 Admin 這個帳號底下,**新建的 `user` 看不到**。要全機安裝就在 `ArgumentList` 加 `'/ALLUSERS'`。
|
||||
- **抓的是 latest 版**:每次部署抓當下最新版。要鎖版本改用 `https://updates.tdesktop.com/tsetup/tsetup-x64.X.Y.Z.exe` 直鏈。
|
||||
- **順序不能搬到 reboot 後**:`shutdown /r /t 5` 只是排程重開機、立即回傳,若放在 Telegram 前面,下載安裝會被 5 秒後的關機砍掉。
|
||||
|
||||
### 上次部署 Telegram 無聲失敗如何排查
|
||||
|
||||
這次每一條都有 log:登入 `Admin` 後看
|
||||
|
||||
```
|
||||
notepad C:\Windows\Temp\firstlogon-telegram.log
|
||||
notepad C:\Windows\Temp\firstlogon-sshd.log
|
||||
```
|
||||
|
||||
常見會看到的值:
|
||||
|
||||
| Log 內容 | 代表 | 對策 |
|
||||
|---|---|---|
|
||||
| `NetWait=60s` + `ERR ...` | 60 秒內 ICMP 沒通,後面可能也失敗 | 接網路線、或在 OOBE 後手動連 Wi-Fi 後重跑指令 |
|
||||
| `Downloaded 0B` 或 `ERR` 含 `SSL/TLS` | TLS 交握失敗 | 檢查系統時間是否對;老機器可能要裝 Windows Update for TLS 1.2 |
|
||||
| `Exit 0` 但桌面沒 Telegram 捷徑 | 裝成功但 per-user 安裝、不是登入那個帳號 | 以 Admin 登入,捷徑在 `%APPDATA%\Microsoft\Windows\Start Menu\Programs\Telegram Desktop` |
|
||||
| 完全沒 log 檔 | 這條 `SynchronousCommand` 根本沒跑(通常是 `AutoLogon.Enabled=false` 或 XML 沒注入) | 查 `C:\Windows\Panther\UnattendGC\setupact.log` |
|
||||
|
||||
---
|
||||
|
||||
## 本次部署已知限制
|
||||
|
||||
@@ -101,9 +101,10 @@ Ventoy 支援寫進 VHD/VDI,可直接掛進 Hyper-V / VirtualBox 當第一顆
|
||||
| 磁碟分割 + 映像展開 | 「正在安裝 Windows」百分比 | 5–15 分鐘 |
|
||||
| 第一次重開 | 黑屏 → 「請稍候」 | 1–2 分鐘 |
|
||||
| OOBE 略過 | **不該出現任何選單**;直接跳過 | 秒殺 |
|
||||
| AutoLogon | 以 `Admin` 自動登入到桌面 | — |
|
||||
| FirstLogonCommands | 閃出 PowerShell 視窗跑 `Setup.ps1` | 看腳本內容 |
|
||||
| AutoLogon | 以 `Admin` 自動登入到桌面(顯示名稱是「Administrator」) | — |
|
||||
| FirstLogonCommands | 閃過一連串 PowerShell / cmd 黑視窗(`Setup.ps1`、建 user 帳號、裝 OpenSSH、裝 Telegram) | 1–3 分鐘(含 FoD 下載) |
|
||||
| 重開機 | 5 秒倒數後重啟 | — |
|
||||
| 第二次開機 | 看到登入畫面,有 `Administrator`(= `Admin` 帳號)和 `user` 兩個選項 | — |
|
||||
|
||||
**正常就是全程不需要碰鍵盤滑鼠。** 如果中途卡在 OOBE 畫面要你選語系/建帳號 → 去看第 5 節除錯。
|
||||
|
||||
@@ -111,7 +112,7 @@ Ventoy 支援寫進 VHD/VDI,可直接掛進 Hyper-V / VirtualBox 當第一顆
|
||||
|
||||
## 4. 部署後善後
|
||||
|
||||
第一次自動登入完成後,建議做這三件事:
|
||||
第一次自動登入完成後,建議做這幾件事:
|
||||
|
||||
1. **刪除殘留的回應檔**(含明碼密碼):
|
||||
```powershell
|
||||
@@ -125,7 +126,14 @@ Ventoy 支援寫進 VHD/VDI,可直接掛進 Hyper-V / VirtualBox 當第一顆
|
||||
reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v AutoAdminLogon
|
||||
```
|
||||
|
||||
3. **改密碼**:範本密碼 `P@ssw0rd!` 是給自動化用的,上線前換掉。
|
||||
3. **改密碼**:範本的 `Admin/P@ssw0rd!` 和 `user/1234` 都是給自動化用的,上線前換掉。`user` 登入時會被強制改密,`Admin` 要自己 `net user Admin *` 改。
|
||||
|
||||
4. **看一下 FirstLogon log**(本輪新增):
|
||||
```powershell
|
||||
notepad C:\Windows\Temp\firstlogon-sshd.log # OpenSSH 安裝結果
|
||||
notepad C:\Windows\Temp\firstlogon-telegram.log # Telegram 下載與安裝結果
|
||||
```
|
||||
`Exit 0` 才是真的成功。前一輪 Telegram 無聲失敗就是因為當時沒有 log、無從判斷。
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -57,8 +57,10 @@ Windows Setup 在不同階段套用不同 `<settings pass="...">`:
|
||||
1. `powershell.exe -ExecutionPolicy Bypass -File C:\Scripts\Setup.ps1`
|
||||
2. `cmd.exe /c net accounts /maxpwage:unlimited`(密碼永不過期)
|
||||
3. `Rename-Computer` 改主機名成 `PC-XXXXX`(重開後生效)
|
||||
4. 下載 `https://telegram.org/dl/desktop/win64` 並以 `/VERYSILENT /SUPPRESSMSGBOXES /NORESTART` 靜默安裝 Telegram Desktop(per-user,裝到 Admin 帳號下)
|
||||
5. `shutdown /r /t 5`(重開機)
|
||||
4. 建立本機帳號 `user`(密碼 `1234`,`net user /logonpasswordchg:yes` 強制首次登入改密)
|
||||
5. 等網路→`Add-WindowsCapability OpenSSH.Server` 安裝並 `Set-Service sshd Automatic` / `Start-Service sshd`(log 寫到 `C:\Windows\Temp\firstlogon-sshd.log`)
|
||||
6. 等網路→下載 `https://telegram.org/dl/desktop/win64` 並以 `/VERYSILENT /SUPPRESSMSGBOXES /NORESTART` 靜默安裝 Telegram(log 寫到 `C:\Windows\Temp\firstlogon-telegram.log`)
|
||||
7. `shutdown /r /t 5`(重開機)
|
||||
|
||||
---
|
||||
|
||||
|
||||
16
SUMMARY.md
16
SUMMARY.md
@@ -44,16 +44,20 @@ XML 能做的事有上限。超過這條線(裝軟體、設 Registry、拉 Git
|
||||
`FirstLogonCommands` 就是交棒點:
|
||||
|
||||
```
|
||||
Order 1 → Setup.ps1 (所有「後續設定」都塞這裡)
|
||||
Order 2 → net accounts (一行搞定的雜事直接 cmd)
|
||||
Order 3 → Rename-Computer (主機名改 PC-XXXXX,重開後生效)
|
||||
Order 4 → Telegram 靜默安裝 (下載 tsetup.exe + /VERYSILENT)
|
||||
Order 5 → shutdown /r (重開機收尾,讓 rename 生效)
|
||||
Order 1 → Setup.ps1 (所有「後續設定」的預留入口)
|
||||
Order 2 → net accounts (一行搞定的雜事直接 cmd)
|
||||
Order 3 → Rename-Computer (主機名改 PC-XXXXX,重開後生效)
|
||||
Order 4 → net user user 1234 /add (建立一般使用者,強制首次登入改密)
|
||||
Order 5 → Add-WindowsCapability OpenSSH (等網路→安裝並啟動 sshd)
|
||||
Order 6 → Telegram 靜默安裝 (等網路→下載 tsetup.exe + /VERYSILENT)
|
||||
Order 7 → shutdown /r (重開機收尾,讓 rename 生效)
|
||||
```
|
||||
|
||||
這讓 `unattend.xml` 保持「只負責 Windows 本身的安裝」,其他事情外包給腳本。職責分離之後,改軟體清單不需要動 XML,改部署流程也不需要動 Setup 邏輯。
|
||||
|
||||
> Telegram 這條是「交棒到腳本」這條原則的例外:**單一套件、需求穩定**的情況下,直接在 `FirstLogonCommands` 裡下載安裝比起硬塞進 `Setup.ps1` 單純。一旦要裝的東西變成清單(3+ 個套件、要版本鎖定、要錯誤處理),就該整批移進 `Setup.ps1` 或改用 winget/choco。
|
||||
> Order 5、6(OpenSSH、Telegram)是「交棒到腳本」這條原則的例外:**單一套件、需求穩定**的情況下,直接在 `FirstLogonCommands` 裡下載安裝比起硬塞進 `Setup.ps1` 單純。一旦要裝的東西變成清單(3+ 個套件、要版本鎖定、要錯誤處理),就該整批移進 `Setup.ps1` 或改用 winget/choco。
|
||||
>
|
||||
> Order 5、6 共用「等 ICMP 通到 8.8.8.8、最多 60 秒」的網路等待迴圈,並且各自把結果寫到 `C:\Windows\Temp\firstlogon-*.log`,避免前一輪 Telegram 無聲失敗的情況再發生。
|
||||
|
||||
---
|
||||
|
||||
|
||||
16
unattend.xml
16
unattend.xml
@@ -168,12 +168,24 @@
|
||||
</SynchronousCommand>
|
||||
<SynchronousCommand wcm:action="add">
|
||||
<Order>4</Order>
|
||||
<CommandLine>powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "$ProgressPreference='SilentlyContinue'; $p=Join-Path $env:TEMP 'tsetup.exe'; Invoke-WebRequest -UseBasicParsing -Uri 'https://telegram.org/dl/desktop/win64' -OutFile $p; Start-Process -FilePath $p -ArgumentList '/VERYSILENT','/SUPPRESSMSGBOXES','/NORESTART' -Wait"</CommandLine>
|
||||
<Description>下載並靜默安裝 Telegram Desktop</Description>
|
||||
<CommandLine>cmd.exe /c "net user user 1234 /add & net user user /logonpasswordchg:yes"</CommandLine>
|
||||
<Description>建立本機帳號 user(密碼 1234,首次登入強制改密)</Description>
|
||||
<RequiresUserInput>false</RequiresUserInput>
|
||||
</SynchronousCommand>
|
||||
<SynchronousCommand wcm:action="add">
|
||||
<Order>5</Order>
|
||||
<CommandLine>powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "$log='C:\Windows\Temp\firstlogon-sshd.log'; $i=0; while ($i -lt 30 -and -not (Test-Connection 8.8.8.8 -Count 1 -Quiet -EA 0)) { Start-Sleep 2; $i++ }; ('NetWait=' + ($i*2) + 's') | Out-File $log -Append; try { Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0 -EA Stop | Out-Null; Set-Service sshd -StartupType Automatic -EA Stop; Start-Service sshd -EA Stop; ('OK ' + (Get-Date -Format o)) | Out-File $log -Append } catch { ('ERR ' + $_.Exception.Message) | Out-File $log -Append }"</CommandLine>
|
||||
<Description>等網路→安裝並啟用 OpenSSH Server(log: firstlogon-sshd.log)</Description>
|
||||
<RequiresUserInput>false</RequiresUserInput>
|
||||
</SynchronousCommand>
|
||||
<SynchronousCommand wcm:action="add">
|
||||
<Order>6</Order>
|
||||
<CommandLine>powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "$log='C:\Windows\Temp\firstlogon-telegram.log'; [Net.ServicePointManager]::SecurityProtocol=[Net.SecurityProtocolType]::Tls12; $ProgressPreference='SilentlyContinue'; $p=Join-Path $env:TEMP 'tsetup.exe'; $i=0; while ($i -lt 30 -and -not (Test-Connection 8.8.8.8 -Count 1 -Quiet -EA 0)) { Start-Sleep 2; $i++ }; ('NetWait=' + ($i*2) + 's') | Out-File $log -Append; try { ('Start ' + (Get-Date -Format o)) | Out-File $log -Append; Invoke-WebRequest -UseBasicParsing -Uri 'https://telegram.org/dl/desktop/win64' -OutFile $p; ('Downloaded ' + (Get-Item $p).Length + 'B') | Out-File $log -Append; $proc=Start-Process -FilePath $p -ArgumentList '/VERYSILENT','/SUPPRESSMSGBOXES','/NORESTART' -Wait -PassThru; ('Exit ' + $proc.ExitCode) | Out-File $log -Append } catch { ('ERR ' + $_.Exception.Message) | Out-File $log -Append }"</CommandLine>
|
||||
<Description>下載並靜默安裝 Telegram Desktop(log: firstlogon-telegram.log)</Description>
|
||||
<RequiresUserInput>false</RequiresUserInput>
|
||||
</SynchronousCommand>
|
||||
<SynchronousCommand wcm:action="add">
|
||||
<Order>7</Order>
|
||||
<CommandLine>shutdown /r /t 5</CommandLine>
|
||||
<Description>完成後重開機</Description>
|
||||
</SynchronousCommand>
|
||||
|
||||
Reference in New Issue
Block a user