From 7421906fb9b2ad10ea26e88b0df29ffe9af43b11 Mon Sep 17 00:00:00 2001 From: HenryDu8133 <813367384@qq.com> Date: Sun, 6 Sep 2026 09:35:33 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20Ubuntu=2024.04=20?= =?UTF-8?q?=E4=B8=8B=20setup-deploy-user.sh=20useradd=20=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E9=94=99=E8=AF=AF=EF=BC=88--disabled-password=20=E6=98=AF=20ad?= =?UTF-8?q?duser=20=E7=9A=84=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/setup-deploy-user.sh | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) 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