sudo works as follows:
1, when the user executes sudo, the system will proactively look for the/etc/sudoers file to determine if the user has permission to execute sudo
2. After confirming that the user has permission to execute sudo, let the user enter the password confirmation
3, if password input is successful, execute sudo follow-up command
4,root do not need to enter a password when executing sudo (the "root all= (All) all" rule in the corresponding configuration file)
5, if you want to switch the identity of the performer is the same, do not need to enter a password
Use Vim to edit/etc/sudoers, or edit sudo rules directly using Visudo
Add a rule:
User01 all= (root) /etc/init.d/httpd
If you do not want to enter a password each time, you can set the following:
User01 all= (Root) nopasswd: /etc/init.d/httpd
Linux normal users start and stop Apache service with sudo privileges