添加root权限脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
#!/bin/bash
chmod 700 /etc/sudoers
declare NAME
visudo=/usr/sbin/visudo
read -p "Please input you want add user in sudo:" OPT
NAME=(`echo $OPT | awk 'BEGIN {ORS=" "} {for (i=1;i<=NF;i++) {print $i}}'`)
#echo ${NAME}
COUNT=$((${#NAME}-1))
for i in `seq 0 $COUNT`; do
#cat /etc/sudoers
sed -i /^root[]*ALL*/a\ "${NAME} ALL=(ALL) ALL" /etc/sudoers
done
chmod 440 /etc/sudoers