Linux promotes user privileges so that users do not need to enter a password when using sudo commands

Enable users to usernameexecute sudo commands without entering a password

  1. Use the visudomodified /etc/suduoersfile, root ALL=(ALL) ALLadd the following content
username ALL=(ALL)       NOPASSWD:ALL
  1. Use shell scripts to modify /etc/suduoersfiles
# 函数
_set_user_privileges(){
    
    
    chmod 777 /etc/sudoers
    echo "$1 ALL=(ALL)       NOPASSWD:ALL" >> /etc/sudoers
    chmod 440 /etc/sudoers
}

# 调用方法
_set_user_privileges "username"

Guess you like

Origin blog.csdn.net/macaiyun0629/article/details/108411282