#!/bin/bash
groupadd -g 3000 readonly
#添加root用户到wheel组
gpasswd -a root wheel
useradd -u 301 -g root -G wheel rescue
useradd -u 302 -g root -G wheel appservice
useradd -u 3001 -g readonly osreadonly
#生成强密码
generate_passwd() {
echo $(< /dev/urandom tr -dc 'A-Za-z0-9!@#$%^&*()_+' |head -c14 )
}
#修改用户密码
users=("root" "rescue" "appservice" "osreadonly")
for i in "${users[@]}";do
password=$(generate_passwd)
echo "$password" |passwd --stdin $users > /dev/null 2>&1
echo "Username:$user Password:$password" |tee -a /tmp/$HOSTNAME-password.log
done
chage -M 30 root
chage -M 99999 rescue
chage -M 30 appservice
chage -M 30 osreadonly
mkdir -p /data/app
mkdir -p /data/backup/{rebootlog,script,os}
chown -R appservice:root /data/{app,backup}
Shell脚本案例——新建用户
于 2023-12-08 17:45:13 首次发布