shell添加用户时设置密码脚本

分类:shell编程 阅读:62020 次

vi useradd.sh
#!/bin/bash
i=1
while [ $i -le 5 ]
do
useradd red$i
a=`sh ./passwd.sh`
echo " red$i:$a " >> userpasswd
echo red$i:$a|chpasswd
let i++
done

执行:sh useradd.sh

[root@2 shell]# cat /etc/passwd|grep red
red1:x:515:515::/home/red1:/bin/bash
red2:x:516:516::/home/red2:/bin/bash
red3:x:517:517::/home/red3:/bin/bash
red4:x:518:518::/home/red4:/bin/bash
red5:x:519:519::/home/red5:/bin/bash
[root@2 shell]# cat userpasswd
red1:$Ca7%298d2
red2:eEaBBB7Fb4
red3:%3E385cecE
red4:3@F%@B0584
red5:AdEe^6BF$F
[root@2 shell]# su red1
[red1@2 shell]$ su red2
口令:
[red2@2 shell]$

##############passwh.sh在本博客中的 shell随机生成十位密码脚本 ############