創建用戶設置隨機密碼
阿新 • • 發佈:2018-05-10
shell linux運維 雲計算 #!/bin/bash
####我們在這以8位為例
x=abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789
for i in {1..8}
do
NUM=$[RANDOM%62]
PASS=${x:NUM:1}
PASS1=${PASS1}$PASS
done ] && exit
useradd $user
####我們在這以8位為例
x=abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789
for i in {1..8}
do
NUM=$[RANDOM%62]
PASS=${x:NUM:1}
PASS1=${PASS1}$PASS
done
read -p "請輸入您創建的用戶名:" user
[ -z $user ] && exit
[ ! -z echo $user | awk ‘{print $2}‘
] && exit
[ ! -z echo $user | sed ‘s#[0-9]##g‘ | sed ‘s#[a-Z]##g‘
useradd $user
echo "$PASS1" | passwd --stdin $user > /dev/null
echo -e "$PASS1\t$user" >> mail.txt ####### 管理員備份
read -p "請輸入您的郵箱帳號:" mail
echo "用戶:$user 密碼:$PASS1" | mail -s "新建用戶$user的密碼" -r admin $mail
#######新手第一次寫 多多指教
創建用戶設置隨機密碼