el: 删除国产系统镜像的默认账户,防止使用默认账户密码登录 ssh

This commit is contained in:
bin456789 2024-07-12 12:40:04 +08:00
parent 6fd3f18b54
commit fc12aa67ab
No known key found for this signature in database
GPG Key ID: EE301B386DE6C11B

View File

@ -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