這是我的 sudoers 文件。我正在使用 sudo visudo 訪問它。我已經添加了這個新用戶'使用者' 然後登出/登入回系統,但該使用者仍需要密碼才能執行 sudo 命令。
## Next comes the main part: which users can run what software on
## which machines (the sudoers file can be shared between multiple
## systems).
## Syntax:
##
## user MACHINE=COMMANDS
##
## The COMMANDS section may have other options added to it.
##
## Allow root to run any commands anywhere
root ALL=(ALL) ALL
user ALL=(ALL) NOPASSWD: ALL
## Allows members of the 'sys' group to run networking, software,
## service management apps and more.
# %sys ALL = NETWORKING, SOFTWARE, SERVICES, STORAGE, DELEGATING, PROCESSES, LOCATE, DRIVERS
## Allows people in group wheel to run all commands
%wheel ALL=(ALL) ALL
## Same thing without a password
# %wheel ALL=(ALL) NOPASSWD: ALL
## Allows members of the users group to mount and unmount the
## cdrom as root
# %users ALL=/sbin/mount /mnt/cdrom, /sbin/umount /mnt/cdrom
## Allows members of the users group to shutdown this system
# %users localhost=/sbin/shutdown -h now
## Read drop-in files from /etc/sudoers.d (the # here does not mean a comment)
#includedir /etc/sudoers.d
答案1
由於 visudo 檔案的建構和順序,並且當您確認使用者是「wheel」群組的成員時 - visudo 檔案應用最後的適用權限。
所以你設定用戶沒有密碼。
但是,wheel 群組(使用者是其中的成員)需要密碼。此設定獲勝,因為這是在您告訴用戶不使用密碼之後設定的。
如果您希望用戶沒有密碼來運行 sudo:
- 放在
user ALL=(ALL) NOPASSWD: ALL
這條線下方%wheel ALL=(ALL) ALL
或 - 從「wheel」群組中刪除使用者。