#! /bin/bash echo "创建的用户:" > /root/jiao/username.txt read -ep "输入要创建的用户:" num for i in `seq 1 $num` do pw= `cat /dev/urandom | head -1|md5sum |head -c 5` id wg$i > /dev/null 2>&1 if [ $? -eq 0 ];then while true do read -ep "wg$i用户已存在,是否删除此用户(y/n):" select case $select in y|Y) userdel -rf wg$i > /dev/null echo "wg$i删除成功" break ;; n|N) break ;; *) echo "输入有误,重输" esac done else useradd wg$i > /dev/null 2>&1 if [ $? -eq 0 ];then echo "wg$i用户创建成功" echo "wg$pw" | passwd --stdin wg$i echo "wg$i $pw" >> /root/username else echo "用户创建失败" fi fi done
passwd --stdin 是标准输入的意思