我不认为这是重复的,因为
这篇文章的主要目的是找到一种方法,使Mac OS X管理员用户无需输入密码即可运行特定的
sudo
命令。
我在Mac OS X上。我运行whoami
,看到bheng
,并且是管理员。
然后我打开该文件 / etc / sudoers sudo visudo
在“用户权限规范”部分中,我添加了
bheng ALL =(ALL)ALL
喜欢
##
## Groups of users. These may consist of user names, uids, Unix groups,
## or netgroups.
# User_Alias ADMINS = millert, dowdy, mikef
##
## Cmnd alias specification
##
## Groups of commands. Often used to group related commands together.
# Cmnd_Alias PROCESSES = /usr/bin/nice, /bin/kill, /usr/bin/renice, \
# /usr/bin/pkill, /usr/bin/top
##
## Defaults specification
##
Defaults env_reset
Defaults env_keep += "BLOCKSIZE"
Defaults env_keep += "COLORFGBG COLORTERM"
Defaults env_keep += "__CF_USER_TEXT_ENCODING"
Defaults env_keep += "CHARSET LANG LANGUAGE LC_ALL LC_COLLATE LC_CTYPE"
Defaults env_keep += "LC_MESSAGES LC_MONETARY LC_NUMERIC LC_TIME"
Defaults env_keep += "LINES COLUMNS"
Defaults env_keep += "LSCOLORS"
Defaults env_keep += "SSH_AUTH_SOCK"
Defaults env_keep += "TZ"
Defaults env_keep += "DISPLAY XAUTHORIZATION XAUTHORITY"
Defaults env_keep += "EDITOR VISUAL"
Defaults env_keep += "HOME MAIL"
Defaults lecture_file = "/etc/sudo_lecture"
##
## Runas alias specification
##
##
## User privilege specification
##
root ALL=(ALL) ALL
bheng ALL=(ALL) ALL
%admin ALL=(ALL) ALL
## Uncomment to allow members of group wheel to execute any command
# %wheel ALL=(ALL) ALL
## Same thing without a password
# %wheel ALL=(ALL) NOPASSWD: ALL
## Uncomment to allow members of group sudo to execute any command
# %sudo ALL=(ALL) ALL
## Uncomment to allow any user to run sudo if they know the password
## of the user they are running the command as (root by default).
# Defaults targetpw # Ask for the password of the target user
# ALL ALL=(ALL) ALL # WARNING: only use this together with 'Defaults targetpw'
## Read drop-in files from /private/etc/sudoers.d
## (the '#' here does not indicate a comment)
#includedir /private/etc/sudoers.d
~
我似乎仍然无法运行sudo命令,例如testing.sh
sudo echo "
<VirtualHost *:80 >
ServerName qwerty.test
VirtualDocumentRoot "/Users/bheng/Sites/laravel/qwerty/public"
UseCanonicalName Off
</VirtualHost>
" >> /etc/apache2/extra/httpd-vhosts.conf
sudo apachectl -k restart
运行sh testing.sh
时我一直得到
testing.sh: line 1: /etc/apache2/extra/httpd-vhosts.conf: Permission denied
httpd not running, trying to start
(48)Address already in use: AH00072: make_sock: could not bind to address [::]:80
(48)Address already in use: AH00072: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
AH00015: Unable to open logs
如何允许这一点?
我已经尝试过此更新的代码
sudo echo "
<VirtualHost *:80 >
ServerName qwerty.test
VirtualDocumentRoot "/Users/bheng/Sites/laravel/qwerty/public"
UseCanonicalName Off
</VirtualHost>
" | sudo tee --append /etc/apache2/extra/httpd-vhosts.conf
apachectl -k restart
尝试运行
⚡️ laravel sh testing.sh
Password:
我再次提示我输入密码吗?