Ben*_*Ben 12 sudo www-data git
我想允许 git 以用户“www-data”的身份运行“git pull”。据我所理解
git ALL=(www-data) git pull
Run Code Online (Sandbox Code Playgroud)
在 /etc/sudoers 中应该可以。
遗憾的是,我收到此行的语法错误,并且 visudo 语法高亮显示在“www-data”中的“-”之后中断
在 /etc/sudoers 用户名中找不到有关禁用“-”的信息。有小费吗?
Ale*_*exD 12
您需要为 'git' 命令使用完整路径名,以下几行不会在 visudo 中产生语法错误并且工作正常。
git ALL = (www-data) /usr/bin/git pull
小智 9
请注意,我使用的是git用户名,因此,如果您使用的是gitosis或任何其他用户名,只需填写您的用户名即可!
在root用户的控制台中执行此命令:
visudo
Run Code Online (Sandbox Code Playgroud)
“vi”编辑器将被打开。添加这些行:
Defaults:git !authenticate
git ALL=(www-data) ALL
Run Code Online (Sandbox Code Playgroud)
结果文件(通过调用“visudo”在“vi”编辑器中打开)应该如下所示:
# /etc/sudoers
#
# This file MUST be edited with the 'visudo' command as root.
#
# See the man page for details on how to write a sudoers file.
#
Defaults env_reset
Defaults:git !authenticate
# Host alias specification
# User alias specification
# Cmnd alias specification
# User privilege specification
root ALL=(ALL) ALL
git ALL=(www-data) ALL
# Allow members of group sudo to execute any command
# (Note that later entries override this, so you might need to move
# it further down)
%sudo ALL=(ALL) ALL
#
#includedir /etc/sudoers.d
Run Code Online (Sandbox Code Playgroud)
然后按 CTRL+O 保存文件,然后按 Enter 接受文件名(bla bla bla),然后按 CTRL+X 关闭“vi”编辑器。
瞧!现在git用户可以作为www-data用户执行命令:
sudo -u www-data git pull origin master
Run Code Online (Sandbox Code Playgroud)