headless
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chineseheadless
无头机器
Guide the user through setting up one headless machine over SSH. Go one
step at a time: say what the step does, run it, show its result, and only
then move on. Every step is safe to run again.
This version covers Macs (steps 1 to 7), Linux machines ("Linux
machines" below) and Windows machines ("Windows machines" below); step 2
and the rules are shared.
All scripts live in this skill's folder; call them by path.
below means this skill's folder.
scripts/$SKILL通过 SSH 指导用户设置一台无头机器。逐步进行:说明每个步骤的作用,运行该步骤并展示结果,然后才继续。每一步都可以安全地重复运行。
本版本涵盖 Mac(步骤 1 到 7)、Linux 机器(见下文“Linux 机器”)和 Windows 机器(见下文“Windows 机器”);步骤 2 和通用规则共用。
所有脚本都位于此 skill 的 文件夹中;应按路径调用。下文 表示此 skill 的文件夹。
scripts/$SKILLRules that never bend
永不妥协的规则
- Never see the password. Do not ask the user to type it to you, paste
it, or put it in a file you read. Never run a command that prints a
secret (,
op read,bw geton the env file,cat,secret-run.sh ... -- cat). You only handle the store entry name, such asecho $.... The scripts read the secret themselves and pipe it toav:HEADLESS_MAC_PASSWORDor SSH; it never reaches a command line or a log.sudo -S - Never weaken sudo. Do not add a passwordless sudo rule. Every later admin step reads the password from the store again.
- Key before key-only. Password sign-in turns off only after
has proved the user's key works.
connect.sh - Ask before anything the user did not choose, and stop and ask when a step fails in a way its message does not explain.
- 绝不查看密码。 不要要求用户把密码输入给你、粘贴给你,或放入你读取的文件中。绝不运行会打印 secret 的命令(、
op read、对 env 文件执行bw get、cat、secret-run.sh ... -- cat)。你只处理 store 的条目名称,例如echo $...。脚本会自行读取 secret,并将其通过管道传给av:HEADLESS_MAC_PASSWORD或 SSH;secret 绝不会出现在命令行或日志中。sudo -S - 绝不削弱 sudo。 不添加免密 sudo 规则。之后的每个管理员步骤都要再次从 store 读取密码。
- 先配置密钥,再启用仅密钥登录。 只有在 证明用户的密钥可用之后,才关闭密码登录。
connect.sh - 对于用户未选择的任何操作,先征得同意;如果某一步以错误消息未作解释的方式失败,则停止并询问用户。
Step 1: Admin access at the Mac (the user does this)
步骤 1:Mac 上的管理员访问权限(由用户操作)
Ask the user to confirm, at the Mac itself (screen and keyboard, or screen
sharing), that:
- It has an administrator account with a password. Note its account
name (short name, such as ).
admin - Remote Login is on for that account: System Settings > General > Sharing > Remote Login (and "Allow full disk access for remote users" may stay off).
- They know its address: an IP address or a name such as
(System Settings > General > Sharing shows it).
mac-mini.local - FileVault may stay on: with automatic sign-in, step 5 turns it off (it has to be off for that) and asks them only if macOS refuses.
Details and screenshots-free wording for each: .
references/mac.md请用户直接在 Mac 本机(显示器和键盘,或屏幕共享)确认:
- 它有一个带密码的管理员账户。记下账户名称(短名称,例如 )。
admin - 该账户已启用远程登录:系统设置 > 通用 > 共享 > 远程登录(“允许远程用户完全磁盘访问权限”可以保持关闭)。
- 用户知道它的地址:IP 地址或名称,例如 (系统设置 > 通用 > 共享中会显示)。
mac-mini.local - FileVault 可以保持开启:启用自动登录时,步骤 5 会将其关闭(自动登录要求 FileVault 处于关闭状态),并且仅在 macOS 拒绝操作时询问用户。
每个选项的详细说明和无需截图的指导措辞见 。
references/mac.mdStep 2: The password goes in a secret store (the user does this)
步骤 2:将密码保存到 secret store(由用户操作)
Ask which secret store they use, recommend one, and have them save the
admin password there. Read for each store's exact
save command and the entry name format. In order of preference:
references/secrets.md| Store | Entry name you keep |
|---|---|
| Automic Vault (macOS) | |
| 1Password CLI | |
| Bitwarden CLI | |
| Any command that prints it | |
| Last resort: a private env file | |
For the env file, tell the user plainly: it is a plain-text file only their
account can read; you will not open it, and they can add a rule to your
settings that denies reading it (), but a program
running as them could still read it. Prefer a real store.
references/secrets.mdAlso make sure the user has an SSH key on this computer
(). If not, offer to make one with
(the user chooses its passphrase). The scripts sign
in without prompts, so a key with a passphrase must be loaded in ssh-agent:
ask the user to run (on a Mac,
keeps it across restarts).
~/.ssh/id_ed25519.pubssh-keygen -t ed25519ssh-add ~/.ssh/id_ed25519ssh-add --apple-use-keychain ~/.ssh/id_ed25519询问用户使用哪个 secret store,推荐一个,并让用户自己将管理员密码保存在其中。读取 ,了解每个 store 的准确保存命令和条目名称格式。按以下顺序推荐:
references/secrets.md| Store | 你保留的条目名称 |
|---|---|
| Automic Vault(macOS) | |
| 1Password CLI | |
| Bitwarden CLI | |
| 任意用于打印密码的命令 | |
| 最后手段:私有 env 文件 | |
对于 env 文件,应明确告诉用户:这是一个只有其账户才能读取的纯文本文件;你不会打开它,用户还可以在设置中添加拒绝读取它的规则(),但以该用户身份运行的程序仍可读取它。应优先使用真正的 store。
references/secrets.md此外,确认用户在这台电脑上拥有 SSH 密钥()。如果没有,可以提出使用 创建一个(由用户选择其 passphrase)。脚本会以无提示方式登录,因此带 passphrase 的密钥必须加载到 ssh-agent 中:请用户运行 (在 Mac 上, 可让密钥在重启后继续保留)。
~/.ssh/id_ed25519.pubssh-keygen -t ed25519ssh-add ~/.ssh/id_ed25519ssh-add --apple-use-keychain ~/.ssh/id_ed25519Step 3: The config folder
步骤 3:配置文件夹
Ask where the machine's config should live. Default:
, a git folder on this computer that is copied to
the Mac on every update; the user can push it to any git host later. If they
already keep a nix-darwin config elsewhere, see "Your own config" below.
~/headless/<machine-name>Ask these choices, with the defaults in bold:
- Machine name (host name): keep the current one, or a new one.
- Automatic sign-in at start-up: on (needs FileVault off; step 5 turns it off). Say so: the Mac's disk is then no longer protected by the account's password.
- Tailscale: off. Offer it; never require it (step 6). If the Mac already
has the Tailscale app (), keep this off and leave the app as it is;
/Applications/Tailscale.apprefuses to start a second Tailscale.apply.sh - Extras, each on and each can be turned off: ,
neverSleep,startAfterPowerLoss,wakeOnLan,powerNapOff,spotlightOff(siriOffsays what each does).references/mac.md
Then make the folder:
sh
$SKILL/scripts/mac/new-config.sh ~/headless/mini \
--address ADDRESS --login ACCOUNT --password-ref ENTRY \
[--ssh-key ~/.ssh/id_ed25519] [--host-name NAME] [--no-auto-login] \
[--tailscale] [--tailscale-key-ref ENTRY] [--extra-off NAME]...It writes , (the user's own additions go here),
and (address, account, key and store entry;
no secret). Show the user .
flake.nixmachine.nixsettings.jsonheadless.envsettings.json询问用户希望将机器配置存放在哪里。默认位置为:
,这是这台计算机上的一个 Git 仓库目录,每次更新时都会复制到 Mac;用户以后可以将其推送到任意 Git 托管平台。如果用户已经在其他位置维护 nix-darwin 配置,请参阅下文的“使用自己的配置”。
~/headless/<machine-name>询问以下选项,默认值以粗体标出:
- 机器名称(主机名):保持当前名称,或设置新名称。
- 启动时自动登录:开启(需要关闭 FileVault;步骤 5 会将其关闭)。明确告知用户:这样 Mac 的磁盘将不再受账户密码保护。
- Tailscale:关闭。可以向用户提供该选项,但绝不强制启用(步骤 6)。如果 Mac 已安装 Tailscale 应用(),仍保持此选项关闭并保留现有应用;
/Applications/Tailscale.app会拒绝启动第二个 Tailscale。apply.sh - 附加项,每项均为开启,且每项都可以单独关闭:、
neverSleep、startAfterPowerLoss、wakeOnLan、powerNapOff、spotlightOff(siriOff说明了每项的作用)。references/mac.md
然后创建文件夹:
sh
$SKILL/scripts/mac/new-config.sh ~/headless/mini \
--address ADDRESS --login ACCOUNT --password-ref ENTRY \
[--ssh-key ~/.ssh/id_ed25519] [--host-name NAME] [--no-auto-login] \
[--tailscale] [--tailscale-key-ref ENTRY] [--extra-off NAME]...它会写入 、(用户自己的添加内容放在这里)、 和 (包含地址、账户、密钥和 store 条目;不含 secret)。向用户展示 。
flake.nixmachine.nixsettings.jsonheadless.envsettings.jsonStep 4: First sign-in
步骤 4:首次登录
sh
$SKILL/scripts/mac/connect.sh ~/headless/miniIt pins the Mac's SSH host key in the folder's and prints its
fingerprint; offer the user the command to compare it at the Mac. Then it
signs in once with the password from the store, adds the user's public key,
and checks key sign-in works. With Automic Vault the user approves the
request in its window; tell them to expect it.
known_hostssh
$SKILL/scripts/mac/connect.sh ~/headless/mini它会将 Mac 的 SSH 主机密钥固定(pin)在文件夹的 中,并打印其指纹;向用户提供命令,以便他们在 Mac 上进行比对。随后,它会使用 store 中的密码登录一次,添加用户的公钥,并检查密钥登录是否正常。使用 Automic Vault 时,用户需要在其窗口中批准请求;提醒用户留意此请求。
known_hostsStep 5: The admin session
步骤 5:管理员会话
sh
$SKILL/scripts/mac/admin.sh ~/headless/miniIt installs Determinate Nix (pinned version, checked hash) and, when
automatic sign-in is on, stores the sign-in password macOS uses at start-up
(, root-only, and recoverable by anyone with root on the
Mac; say so). If FileVault is on and automatic sign-in is chosen, it turns
FileVault off with the same password and waits until the disk has
decrypted (it can take several minutes; a restart before then would stop
at FileVault's unlock screen). Only when macOS refuses - the account cannot
unlock FileVault, or the organization managing the Mac forbids turning it
off - it stops with a line starting . Pass that on: the user
turns FileVault off at the Mac (or has the Mac's managers allow it), or
sets in ; then run again.
/etc/kcpasswordask the user:"autoLogin": falsesettings.jsonadmin.shsh
$SKILL/scripts/mac/admin.sh ~/headless/mini它会安装 Determinate Nix(固定版本并校验哈希值);启用自动登录时,还会存储 macOS 启动时用于登录的密码(,仅 root 可读,且任何拥有 root 权限的人都能恢复;应明确告知用户)。如果 FileVault 已开启且选择了自动登录,它会使用同一个密码关闭 FileVault,并等待磁盘完成解密(可能需要几分钟;在此之前重启会停在 FileVault 解锁界面)。只有当 macOS 拒绝执行时——账户无法解锁 FileVault,或管理该 Mac 的组织禁止关闭 FileVault——脚本才会停止,并输出一行以 开头的内容。将该内容转达给用户:用户可以在 Mac 上关闭 FileVault(或让 Mac 的管理人员允许关闭),也可以在 中设置 ;然后再次运行 。
/etc/kcpasswordask the user:settings.json"autoLogin": falseadmin.shStep 6: Apply the config
步骤 6:应用配置
sh
$SKILL/scripts/mac/apply.sh ~/headless/miniIt copies the folder to the Mac, builds the system there, and switches to it
with (password from the store again). The first run copies
back into the folder. Then commit the folder:
.
sudo -Sflake.lockgit -C ~/headless/mini add -A && git -C ~/headless/mini commit -m "headless: set up"Tailscale (only if chosen). With
applied:
"tailscale": { "enable": true }sh
$SKILL/scripts/mac/tailscale.sh ~/headless/miniWith set (an auth key in the store) it joins at once.
Otherwise it prints a sign-in link: show it to the user, ask them to open it
and approve the Mac, then run . Details:
.
TAILSCALE_KEY_REFtailscale.sh ~/headless/mini --waitreferences/tailscale.mdsh
$SKILL/scripts/mac/apply.sh ~/headless/mini它会将文件夹复制到 Mac,在 Mac 上构建系统,并通过 切换到新配置(再次从 store 读取密码)。首次运行会将 复制回文件夹。随后提交该文件夹:
。
sudo -Sflake.lockgit -C ~/headless/mini add -A && git -C ~/headless/mini commit -m "headless: set up"Tailscale(仅在用户选择时)。 应用 后:
"tailscale": { "enable": true }sh
$SKILL/scripts/mac/tailscale.sh ~/headless/mini如果设置了 (store 中的 auth key),它会立即加入。否则,它会打印登录链接:向用户展示该链接,请用户打开链接并批准这台 Mac,然后运行 。详情见 。
TAILSCALE_KEY_REFtailscale.sh ~/headless/mini --waitreferences/tailscale.mdStep 7: Verify, restart, verify
步骤 7:验证、重启、再次验证
sh
$SKILL/scripts/mac/verify.sh ~/headless/mini
$SKILL/scripts/mac/restart.sh ~/headless/mini
$SKILL/scripts/mac/verify.sh ~/headless/miniverify.shokFAILn/arestart.shFinish with a short summary: what is on, what is off, where the config
folder is, and how to update (below).
sh
$SKILL/scripts/mac/verify.sh ~/headless/mini
$SKILL/scripts/mac/restart.sh ~/headless/mini
$SKILL/scripts/mac/verify.sh ~/headless/miniverify.shokFAILn/arestart.sh最后给出简短总结:哪些功能已开启、哪些已关闭、配置文件夹位于何处,以及如何更新(见下文)。
Later: updates
后续:更新
Edit or in the config folder, then run
and again. The password is read from the store each
time. Turning an extra off later only stops the config managing it: the
Mac keeps the value the extra set (for example, Spotlight stays off) and
macOS's default does not come back. Tell the user so, and change that
setting at the Mac, or add it to , if they want it back.
To update inputs (nixpkgs, nix-darwin, this module):
on a computer with Nix, or delete
and run .
machine.nixsettings.jsonapply.shverify.shmachine.nixnix flake update --flake ~/headless/miniflake.lockapply.sh在配置文件夹中编辑 或 ,然后再次运行 和 。每次都会从 store 读取密码。以后关闭某个附加项,只会停止配置对它的管理:Mac 会保留该附加项此前设置的值(例如 Spotlight 会继续关闭),macOS 的默认值不会自动恢复。应告知用户这一点;如果用户想恢复该设置,可以在 Mac 上进行更改,或者将其添加到 中。
要更新输入(nixpkgs、nix-darwin、此 module),可在安装了 Nix 的计算机上运行 ,或者删除 后运行 。
machine.nixsettings.jsonapply.shverify.shmachine.nixnix flake update --flake ~/headless/miniflake.lockapply.shYour own config
使用自己的配置
The config folder is an ordinary nix-darwin flake whose
imports .
A user with an existing nix-darwin flake can instead add this repository as
an input, import the module in their own host, set options, and
expose the host as in a folder these scripts
copy; the scripts only need and that output name. See
for the module's options.
darwinConfigurations.machineheadless.darwinModules.headlessheadless.*darwinConfigurations.machineheadless.envreferences/mac.mdOn NixOS it works the same way: the folder's exposes
, which imports
and sets
( lists the options). A folder with its own
is used as it is: copies and builds it and brings
nothing in from . Keep (from )
beside it: checks it and reads the machine's own
record. Expose the host under its host name too if
at the machine should find it without .
flake.nixnixosConfigurations.machineheadless.nixosModules.headlessheadless.*references/linux.mdflake.nixapply.sh/etc/nixossettings.jsonnew-config.shapply.shverify.shnixos-rebuild switch--flake /etc/nixos#machine配置文件夹是一个普通的 nix-darwin flake,其 会导入 。已有 nix-darwin flake 的用户也可以将本仓库添加为 input,在自己的 host 中导入该 module,设置 选项,并在这些脚本所复制的文件夹中将该 host 暴露为 ;脚本只需要 和该输出名称。module 的选项见 。
darwinConfigurations.machineheadless.darwinModules.headlessheadless.*darwinConfigurations.machineheadless.envreferences/mac.md在 NixOS 上的工作方式相同:文件夹的 会暴露 ,导入 并设置 ( 列出了这些选项)。带有自身 的文件夹会按原样使用: 会复制并构建它,不会从 引入任何内容。请将 (由 生成)放在同一目录中: 会检查它, 会读取机器自身的记录。如果希望机器上的 无需使用 就能找到该 host,还应以其主机名暴露该 host。
flake.nixnixosConfigurations.machineheadless.nixosModules.headlessheadless.*references/linux.mdflake.nixapply.sh/etc/nixossettings.jsonnew-config.shapply.shverify.shnixos-rebuild switch--flake /etc/nixos#machineWhen something fails
发生失败时
- Read the script's last line; it says what failed and what to do.
headless:lists the common cases.references/mac.md - A changed host key stops every step on purpose. Ask the user whether the
Mac was reinstalled before removing the folder's .
known_hosts - Never work around a failed step by turning on password sign-in, adding a sudo rule, or printing the secret.
- 读取脚本最后一行 ;它会说明失败原因及处理方式。常见情况见
headless:。references/mac.md - 主机密钥发生变化时,脚本会故意停止所有步骤。删除文件夹中的 前,先询问用户该 Mac 是否重新安装过。
known_hosts - 绝不通过启用密码登录、添加 sudo 规则或打印 secret 来绕过失败的步骤。
Linux machines
Linux 机器
The same rules hold. The scripts are in ; details, options
and failure cases are in .
scripts/linux/references/linux.mdL1. Admin access (the user does this). Ask the user to confirm the
machine runs an SSH server they can reach, has an account with a
password that may use (in the or group), and its
address. Root is not used as the login.
sudosudowheelL2. The password store and key: step 2 above, unchanged.
L3. The config folder. Same questions as step 3, with Linux's extras:
and , each on. Automatic sign-in on Linux
means the account's own session (its user services) starts at boot without
anyone signing in; nothing signs in on a screen.
neverSleepautoUpdatessh
$SKILL/scripts/linux/new-config.sh ~/headless/box \
--address ADDRESS --login ACCOUNT --password-ref ENTRY \
[--ssh-key ~/.ssh/id_ed25519] [--host-name NAME] [--no-auto-login] \
[--tailscale] [--tailscale-key-ref ENTRY] [--extra-off NAME]...L4. First sign-in. ,
as in step 4. Its last lines say which distribution the machine runs and
what comes next.
$SKILL/scripts/linux/connect.sh ~/headless/boxL5. NixOS, or not.
-
It runs NixOS: go to L6. The firstcopies the machine's own
apply.shinto the folder (/etc/nixos), so its boot loader, disks and other settings stay, and the machine stays on the NixOS release it runs (such as 26.05, read from root's channel). Ifnixos/cannot tell the release, it stops; ask the user which one and passapply.sh(or--nixos-branch nixos-26.05). Ask the user to check that copy holds nothing private before they push the folder anywhere. From then on eachnixos-unstableputs the folder inapply.sh(the old one is kept as/etc/nixos), so/etc/nixos.before-headlessand automatic updates at the machine build the same setup; an automatic update takes the newest nixpkgs of the machine's release, and once the machine boots a system built from it,nixos-rebuild switchkeeps that newer one and writes it into the folder'sapply.shto commit.flake.lock -
Any other distribution: offer to replace it with NixOS, using nixos-anywhere. Say plainly: this erases the whole disk, everything on it is gone, and it needs Nix on this computer, an x86_64 or aarch64 machine with 2 GB of memory and Secure Boot off. The machine keeps its address (a fixed one is written into the new setup), SSH host key and the account's password; it needs the machine reached at an IPv4 address on its wired network card, and stops, changing nothing, otherwise. If the user agrees:sh
$SKILL/scripts/linux/install-nixos.sh ~/headless/box --list-disks $SKILL/scripts/linux/install-nixos.sh ~/headless/box --disk /dev/DISK --yes-wipeShow the disk list and have the user name the disk; passonly after they agreed to erase that disk. It takes 5 to 20 minutes.--yes-wipe -
The user keeps their distribution (Debian, Ubuntu or Fedora): go to L6;runs the distro-neutral script instead.
apply.sh
L6. Apply, then verify, restart, verify.
sh
$SKILL/scripts/linux/apply.sh ~/headless/box
$SKILL/scripts/linux/verify.sh ~/headless/box
$SKILL/scripts/linux/restart.sh ~/headless/box
$SKILL/scripts/linux/verify.sh ~/headless/boxOn NixOS builds the system on the machine and switches to it; on
another distribution it runs the script, which prints one line
per change and none when run again. Commit the folder afterwards. For
Tailscale, run as in
step 6. restarts the machine, waits for a new boot, and with
automatic sign-in on checks the session started before anyone signed in.
Tell the user before restarting.
apply.shchanged:$SKILL/scripts/linux/tailscale.sh ~/headless/boxrestart.shUpdates: edit (or on NixOS) and run
and again. Other distributions install updates by themselves
(). On NixOS, delete and run to move
to newer inputs on the same release.
settings.jsonmachine.nixapply.shverify.shautoUpdatesflake.lockapply.sh适用同样的规则。脚本位于 ;详情、选项和失败情况见 。
scripts/linux/references/linux.mdL1. 管理员访问权限(由用户操作)。 请用户确认机器运行着可访问的 SSH server,有一个可使用 的带密码账户(位于 或 组中),并知道其地址。不使用 root 作为登录账户。
sudosudowheel**L2. 密码 store 和密钥:**与步骤 2 相同,不作改动。
L3. 配置文件夹。 与步骤 3 使用相同的问题,并增加 Linux 的附加项:
和 ,两项均为开启。Linux 上的自动登录是指账户自身的 session(其 user services)会在启动时运行,而无需有人在屏幕上登录。
neverSleepautoUpdatessh
$SKILL/scripts/linux/new-config.sh ~/headless/box \
--address ADDRESS --login ACCOUNT --password-ref ENTRY \
[--ssh-key ~/.ssh/id_ed25519] [--host-name NAME] [--no-auto-login] \
[--tailscale] [--tailscale-key-ref ENTRY] [--extra-off NAME]...L4. 首次登录。 ,与步骤 4 相同。其最后几行会说明机器运行的发行版以及后续操作。
$SKILL/scripts/linux/connect.sh ~/headless/boxL5. 使用 NixOS,或不使用。
-
**机器运行 NixOS:**进入 L6。首次运行时,会将机器自身的
apply.sh复制到文件夹中(/etc/nixos),从而保留其 bootloader、磁盘和其他设置,并让机器继续使用当前运行的 NixOS release(例如 26.05,该版本从 root 的 channel 读取)。如果nixos/无法确定 release,它会停止;询问用户具体版本,并传入apply.sh(或--nixos-branch nixos-26.05)。请用户在将文件夹推送到任何位置前检查该副本是否包含隐私数据。从此以后,每次运行nixos-unstable都会将文件夹放入apply.sh(旧版本保留为/etc/nixos),因此机器上的/etc/nixos.before-headless和自动更新会构建相同的配置;自动更新会获取该 release 中最新的 nixpkgs,而机器启动由这些输入构建的系统后,nixos-rebuild switch会保留较新的版本,并将其写入文件夹的apply.sh以供提交。flake.lock -
其他发行版:可以使用 nixos-anywhere 提供将其替换为 NixOS的选项。明确说明:这会擦除整个磁盘,磁盘上的所有内容都会丢失;此操作要求当前计算机已安装 Nix,目标机器为 x86_64 或 aarch64 架构、内存不少于 2 GB,并关闭 Secure Boot。机器会保留其地址(新配置中会写入一个固定地址)、SSH 主机密钥和账户密码;必须能够通过有线网络卡的 IPv4 地址访问机器,否则脚本会停止且不更改任何内容。如果用户同意:sh
$SKILL/scripts/linux/install-nixos.sh ~/headless/box --list-disks $SKILL/scripts/linux/install-nixos.sh ~/headless/box --disk /dev/DISK --yes-wipe展示磁盘列表,并让用户指定磁盘;只有在用户同意擦除该磁盘后,才能传入。整个过程需要 5 到 20 分钟。--yes-wipe -
用户保留现有发行版(Debian、Ubuntu 或 Fedora):进入 L6;会改为运行发行版无关的脚本。
apply.sh
L6. 应用,然后验证、重启、再次验证。
sh
$SKILL/scripts/linux/apply.sh ~/headless/box
$SKILL/scripts/linux/verify.sh ~/headless/box
$SKILL/scripts/linux/restart.sh ~/headless/box
$SKILL/scripts/linux/verify.sh ~/headless/box在 NixOS 上, 会在机器上构建系统并切换到该系统;在其他发行版上,它会运行相应脚本。脚本每项更改都会打印一行 ,重复运行时不会打印任何更改。随后提交文件夹。Tailscale 的处理方式与步骤 6 相同,运行 。 会重启机器并等待新的启动;启用自动登录时,还会检查 session 是否在无人登录前就已启动。重启前要告知用户。
apply.shchanged:$SKILL/scripts/linux/tailscale.sh ~/headless/boxrestart.sh更新:编辑 (NixOS 上则编辑 ),然后再次运行 和 。其他发行版会自行安装更新()。在 NixOS 上,删除 并运行 ,即可在同一 release 上切换到更新的 inputs。
settings.jsonmachine.nixapply.shverify.shautoUpdatesflake.lockapply.shWindows machines
Windows 机器
The same rules hold; an SSH session of an administrator on Windows is
already elevated, so there is no and the password is only read for
automatic sign-in. The scripts are in ; details, options
and failure cases are in .
sudoscripts/windows/references/windows.mdW1. Admin access and OpenSSH Server (the user does this). Ask the user
to confirm, at the PC, that it has a local administrator account with a
password (not a Microsoft account: automatic sign-in and SSH need a local
one), and its address (Settings > Network & internet > Properties).
The account's name may use letters, digits, dots, dashes and underscores
(at most 20; case does not matter). If its name has a space or any other
character, the skill cannot use it: ask the user to make another local
administrator account for it, such as ().
Then ask them to open Windows PowerShell as administrator (right-click
Start > Terminal (Admin)) and paste these lines, which install and start
OpenSSH Server:
headlessreferences/windows.mdpowershell
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
Set-Service -Name sshd -StartupType Automatic
Start-Service sshdThe first line takes a few minutes. OpenSSH's firewall rule
lets SSH in only on a Private network, and Windows makes a new network
Public. Ask whether this network is their home or office network (Settings
Network & internet shows "Public network" or "Private network"); if it is, and it says Public, have them also paste this line, which marks the networks the PC is on now as Private:
powershell
Get-NetConnectionProfile | Set-NetConnectionProfile -NetworkCategory Privatereferences/windows.mdW2. The password store and key: step 2 above, unchanged.
W3. The config folder. Same questions as step 3, with Windows's extras,
each on: , , ,
( says what each does). A
Windows host name is at most 15 characters. takes the account
name as Windows shows it, in any case; a name with a space is refused, so
use the other administrator account from W1.
neverSleeppowerButtonShutsDownhideSleepupdatesOvernightreferences/windows.md--loginsh
$SKILL/scripts/windows/new-config.sh ~/headless/pc \
--address ADDRESS --login ACCOUNT --password-ref ENTRY \
[--ssh-key ~/.ssh/id_ed25519] [--host-name NAME] [--no-auto-login] \
[--tailscale] [--tailscale-key-ref ENTRY] [--extra-off NAME]...It writes , and (the user's
own PowerShell additions, run after the headless settings on every apply).
settings.jsonheadless.envmachine.ps1W4. First sign-in. ,
as in step 4. The key goes in
(readable by Administrators and SYSTEM only). Its last lines say which
Windows the machine runs.
$SKILL/scripts/windows/connect.sh ~/headless/pcC:\ProgramData\ssh\administrators_authorized_keysW5. Apply. copies the
folder to and applies it. It prints one
line per change and none when run again. With automatic sign-in
on, it pipes the password from the store and Windows keeps it as an LSA
secret, never as plain text in the registry; any administrator of the PC
can still read it back (say so). Commit the folder afterwards. For
Tailscale, run as in
step 6; an existing Tailscale install is kept, and sets its
unattended policy so it runs before anyone signs in. One that another
Windows account joined with Run unattended stays that account's; one it
joined without it signs out at the next restart, and then
joins it as the skill's account. To have the skill own it sooner, ask,
then , and
().
$SKILL/scripts/windows/apply.sh ~/headless/pcC:\ProgramData\headlesschanged:$SKILL/scripts/windows/tailscale.sh ~/headless/pcapply.shtailscale.shtailscale.sh ~/headless/pc --uninstallapply.shtailscale.shreferences/windows.mdW6. Verify, restart, verify.
sh
$SKILL/scripts/windows/verify.sh ~/headless/pc
$SKILL/scripts/windows/restart.sh ~/headless/pc
$SKILL/scripts/windows/verify.sh ~/headless/pcA new host name takes effect at this restart. waits for a new
boot and, with automatic sign-in on, for the account to be signed in on
the screen. Tell the user before restarting, and when verify's Tailscale
line says "otherwise it signs out at the next restart", say that this
restart signs it out unless that account chose Run unattended, and that
then joins it as the skill's account.
restart.shtailscale.shUpdates: edit or and run and
again. Windows installs its own updates;
keeps their restarts to the night. Turning an extra off later stops
managing it and leaves the value it set.
settings.jsonmachine.ps1apply.shverify.shupdatesOvernight适用同样的规则;Windows 上管理员的 SSH session 已经具有提升权限,因此没有 ,密码只会在配置自动登录时读取。脚本位于 ;详情、选项和失败情况见 。
sudoscripts/windows/references/windows.mdW1. 管理员访问权限和 OpenSSH Server(由用户操作)。 请用户直接在 PC 上确认:它有一个带密码的本地管理员账户(不能使用 Microsoft 账户:自动登录和 SSH 需要本地账户),并知道其地址(Settings > Network & internet > Properties)。账户名称可以包含字母、数字、点、短划线和下划线(最多 20 个字符;大小写无关)。如果名称中包含空格或其他字符,此 skill 将无法使用它:请用户创建另一个本地管理员账户,例如 ()。
headlessreferences/windows.md然后请用户以管理员身份打开 Windows PowerShell(右键点击 Start > Terminal (Admin)),并粘贴以下命令,以安装和启动 OpenSSH Server:
powershell
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
Set-Service -Name sshd -StartupType Automatic
Start-Service sshd第一行需要几分钟。OpenSSH 的防火墙规则只允许通过 Private 网络连接 SSH,而 Windows 会将新网络设置为 Public。询问该网络是家庭网络还是办公室网络(Settings > Network & internet 会显示“Public network”或“Private network”);如果它显示为 Public,请用户同时粘贴以下命令,将 PC 当前所在网络标记为 Private:
powershell
Get-NetConnectionProfile | Set-NetConnectionProfile -NetworkCategory Private如果某一行失败,应如何处理见 。
references/windows.md**W2. 密码 store 和密钥:**与步骤 2 相同,不作改动。
W3. 配置文件夹。 与步骤 3 使用相同的问题,并增加 Windows 的附加项,每项均为开启:、、、( 说明了每项的作用)。Windows 主机名最多为 15 个字符。 接受 Windows 中显示的账户名称,大小写任意;如果名称中包含空格,命令会被拒绝,因此应使用 W1 中创建的另一个管理员账户。
neverSleeppowerButtonShutsDownhideSleepupdatesOvernightreferences/windows.md--loginsh
$SKILL/scripts/windows/new-config.sh ~/headless/pc \
--address ADDRESS --login ACCOUNT --password-ref ENTRY \
[--ssh-key ~/.ssh/id_ed25519] [--host-name NAME] [--no-auto-login] \
[--tailscale] [--tailscale-key-ref ENTRY] [--extra-off NAME]...它会写入 、 和 (用户自己的 PowerShell 添加内容会在每次 apply 时于 headless 设置之后运行)。
settings.jsonheadless.envmachine.ps1W4. 首次登录。 ,与步骤 4 相同。密钥会被放入 (仅 Administrators 和 SYSTEM 可读取)。其最后几行会说明机器运行的 Windows 版本。
$SKILL/scripts/windows/connect.sh ~/headless/pcC:\ProgramData\ssh\administrators_authorized_keysW5. 应用。 会将文件夹复制到 并应用配置。它每项更改都会打印一行 ,重复运行时不会打印任何更改。启用自动登录时,它会从 store 管道传入密码,Windows 会将其保存为 LSA secret,而不会以明文形式保存在注册表中;PC 上的任何管理员仍可将其读回(应明确告知用户)。随后提交文件夹。
$SKILL/scripts/windows/apply.sh ~/headless/pcC:\ProgramData\headlesschanged:对于 Tailscale,与步骤 6 相同,运行 ;已有的 Tailscale 安装会被保留, 会设置其无人值守策略,使其在任何人登录前运行。如果某个 Windows 账户使用 Run unattended 加入,该安装会继续属于该账户;如果未使用 Run unattended 加入,则会在下次重启时退出,随后 会使用此 skill 的账户重新加入。如需让此 skill 更早接管,请先征得用户同意,然后依次运行 、 和 ()。
$SKILL/scripts/windows/tailscale.sh ~/headless/pcapply.shtailscale.shtailscale.sh ~/headless/pc --uninstallapply.shtailscale.shreferences/windows.mdW6. 验证、重启、再次验证。
sh
$SKILL/scripts/windows/verify.sh ~/headless/pc
$SKILL/scripts/windows/restart.sh ~/headless/pc
$SKILL/scripts/windows/verify.sh ~/headless/pc新主机名会在此次重启时生效。 会等待机器完成新的启动;启用自动登录时,还会等待账户在屏幕上完成登录。重启前要告知用户。当 verify 的 Tailscale 一行提示“否则它会在下次重启时退出”时,应告知用户:此次重启会导致其退出,除非该账户选择了 Run unattended;随后 会使用此 skill 的账户重新加入。
restart.shtailscale.sh更新:编辑 或 ,然后再次运行 和 。Windows 会自行安装更新; 会将更新引起的重启安排在夜间。以后关闭某个附加项只会停止管理该设置,并保留它此前设置的值。
settings.jsonmachine.ps1apply.shverify.shupdatesOvernight