visudo配置NOPASSWD:ALL后执行sudo仍需输入密码的问题求助
Hey there! Let's dig into why your sudo setup isn't skipping the password prompt like you expected.
The most likely culprit here is the order of your sudo rules. Sudo applies rules from top to bottom, and stops at the first matching rule. Looking at your config:
%sudo ALL=(ALL:ALL) ALL
root ALL=(ALL:ALL) ALL
user.jeong ALL=(ALL) NOPASSWD:ALL
If your user.jeong account is part of the sudo group (which is pretty common for default user setups), the %sudo rule (which requires a password) gets matched first, and your NOPASSWD rule never gets used.
How to check this?
Run this command to see which groups your user belongs to:
groups user.jeong
If sudo shows up in the output, that's exactly the issue.
Fix options:
Reorder your rules: Move your user-specific
NOPASSWDrule above the%sudogroup rule. Your config should look like this:Defaults env_reset Defaults mail_badpass Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" user.jeong ALL=(ALL) NOPASSWD:ALL %sudo ALL=(ALL:ALL) ALL root ALL=(ALL:ALL) ALL %wheel ALL=(ALL) LOG_INPUT:LOG_OUTPUT:ALLSave the file with
visudo(always usevisudoto edit sudoers to avoid syntax errors!), log out and back in, and test again.Remove your user from the sudo group: If you don't need your user to be in the sudo group at all, run this command:
gpasswd -d user.jeong sudoThen log out and back in, and your
NOPASSWDrule should take effect.
One last check: Make sure your sudoers file has no syntax errors. Run visudo -c to validate it—if it says "sudoers file parsed OK", you're good to go.
备注:内容来源于stack exchange,提问作者Jerry

