root密码修改
#!/bin/bash ################################# # copyright by hwb # DATE:2020-11-23 # ################################# #redis ROOT_PWD=初始化密码 #调用函数库 [ -f /etc/init.d/functions ] && source /etc/init.d/functions export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin source /etc/profile #Require root to run this script. [ $(id -u) -gt 0 ] && echo "请用root用户执行此脚本!" && exit 1 #用参数指定需清理的路径和清理天数(变量的值非空返回0,为true) if [ -n "$1" ];then ROOT_PWD=$1 echo "root用户设定密码为:$ROOT_PWD" fi # auto install redis-3.2 function pwd_mod() { echo "" echo -e "\033[33m*************************************修改服务器root用户密码****************************************\033[0m" echo "" echo -e "\033[36m Usage: $0 '服务器密码'[注意要添加单引号,防止特殊字符bug] \033[0m" echo "" echo ${ROOT_PWD}| passwd --stdin root # passwd root <<EOF # ${ROOT_PWD} # ${ROOT_PWD} # ${ROOT_PWD} # EOF if [ $? -eq 0 ];then action "成功修改服务器密码: ${ROOT_PWD}" /bin/true else action "无法修改服务器密码" /bin/false exit $? fi echo -e "\033[33m************************************完成服务器root用户密码修改*************************************\033[0m" echo "" } pwd_mod
实现结果