您的位置:首页 > 其它

批量重置用户密码

2015-11-17 20:30 417 查看
需要root 免密到需要修改的机器

#!/bin/bash
#2015-11-11
#reset root passwd @by xbzy

User="$1"
LogFile="modify_passwd_"

function Change_passwd()
{

IP=$1

_passwd=$(head  /dev/urandom |md5sum |head -c 16)

ssh  -o ConnectTimeout=15 -o StrictHostKeyChecking=no -o GSSAPIAuthentication=no  $IP   "echo '$User:${_passwd}' | chpasswd"
test $? -ne 0 && echo -e "\e[1;31mPassword modify Failed\e[0m" &&exit -2||echo -e "Password modify\e[1;32m      [ success ]\e[0m\n"

sed -i "/$IP/d"  $LogFile$User
echo "$(date +%F_%H-%M-%S)      Host:$IP  User:$User      PASS:${_passwd}" |tee -a $LogFile$User

}

function More_IP()
{

#_passwd=$(head  /dev/urandom |md5sum |head -c 16)
List="$1"
for i in `cat $List`
do
echo -e "########$i\n"
#       Change_passwd $i  ${_passwd}
Change_passwd $i
done
}

function One_IP()
{
#        _passwd=$(head  /dev/urandom |md5sum |head -c 16)
Change_passwd $1
}

function Mesage()
{

echo -e "\e[1;32mUsage:sh $0 username IP
:sh $0 username  -f iplist\e[0m"
exit -1
}

if [ $# -ne 2 ] && [ $# -ne 3 ];then
Mesage
fi

if [ "$2" == "-f" ] && [ $# -eq 3 ];then
More_IP $3
elif [ $# -eq 2 ];then
echo $2 |  grep  -E "([a-z]+\-)([a-z]+\-)([a-z]+[0-9]+\.)([a-z])|([0-9]+\.)([0-9]+\.)([0-9]+\.)[0-9]+"  && One_IP $2||Mesage
else
Mesage
fi
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  重置密码