From fc12aa67aba92b229c5c59d778f1e743e73ada42 Mon Sep 17 00:00:00 2001 From: bin456789 Date: Fri, 12 Jul 2024 12:40:04 +0800 Subject: [PATCH] =?UTF-8?q?el:=20=E5=88=A0=E9=99=A4=E5=9B=BD=E4=BA=A7?= =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E9=95=9C=E5=83=8F=E7=9A=84=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E8=B4=A6=E6=88=B7=EF=BC=8C=E9=98=B2=E6=AD=A2=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E9=BB=98=E8=AE=A4=E8=B4=A6=E6=88=B7=E5=AF=86=E7=A0=81=E7=99=BB?= =?UTF-8?q?=E5=BD=95=20ssh?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- trans.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/trans.sh b/trans.sh index f2901c6..46e43df 100644 --- a/trans.sh +++ b/trans.sh @@ -2239,6 +2239,17 @@ chroot_apt_autoremove() { mv $conf.orig $conf } +del_default_user() { + os_dir=$1 + + while read -r user; do + if grep ^$user':\$' "$os_dir/etc/shadow"; then + echo "Deleting user $user" + chroot "$os_dir" userdel -rf "$user" + fi + done < <(grep -v nologin$ "$os_dir/etc/passwd" | cut -d: -f1 | grep -v root) +} + install_qcow_by_copy() { mount_nouuid() { case "$(get_os_fs)" in @@ -2384,6 +2395,9 @@ install_qcow_by_copy() { # resolv.conf cp_resolv_conf /os + # 删除镜像的默认账户,防止使用默认账户密码登录 ssh + del_default_user /os + # selinux kdump disable_selinux_kdump /os