Enable users to username
execute sudo commands without entering a password
- Use the
visudo
modified/etc/suduoers
file,root ALL=(ALL) ALL
add the following content
username ALL=(ALL) NOPASSWD:ALL
- Use shell scripts to modify
/etc/suduoers
files
# 函数
_set_user_privileges(){
chmod 777 /etc/sudoers
echo "$1 ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
chmod 440 /etc/sudoers
}
# 调用方法
_set_user_privileges "username"