diff --git a/scripts/setup-deploy-user.sh b/scripts/setup-deploy-user.sh index 38ac0b1..dc9a48b 100644 --- a/scripts/setup-deploy-user.sh +++ b/scripts/setup-deploy-user.sh @@ -42,8 +42,17 @@ command -v setfacl >/dev/null 2>&1 || { # -------- 1. 建用户 -------- if ! id -u "${DEPLOY_USER}" >/dev/null 2>&1; then - useradd --create-home --shell /usr/bin/bash --disabled-password "${DEPLOY_USER}" - ok "新建用户:${DEPLOY_USER}(无密码,仅 SSH key 登录)" + # 注意:Ubuntu 22.04/24.04 的 useradd 没有 --disabled-password 选项 + # (那是 adduser 命令的参数,之前脚本写错了命令)。 + # 这里用 useradd 原生参数: + # -m = 创建 home + # -s = 指定登录 shell + # -p '*' = 密码设置为「*」(锁定,禁止用密码登录,只能 SSH 密钥) + # 这样和之前「只允许 SSH 密钥登录、无密码」的意图完全一致。 + useradd -m -s /usr/bin/bash -p '*' "${DEPLOY_USER}" + # Ubuntu/Debian 额外保险:锁定密码字段,避免 shadow 被改 + usermod -L "${DEPLOY_USER}" 2>/dev/null || true + ok "新建用户:${DEPLOY_USER}(密码已锁定,仅 SSH key 登录)" else info "用户 ${DEPLOY_USER} 已存在,跳过创建" fi