允许用户'git'通过sudo运行'git pull'作为'www-data'

我想让git运行'git pull'作为用户'www-data'。 据我了解git ALL =(www-data)/ etc / sudoers中的git pull应该使它成为可能。

可悲的是我得到了这条线的语法错误和visudo语法突出显示中的“ – ”在“万维网数据”

在/ etc / sudoers用户名中找不到关于禁止的“ – ”的信息。 任何提示?

你需要使用完整的path名'git'命令,下面的行不会在visudo中产生语法错误,并且正常工作。

git ALL = (www-data) /usr/bin/git pull

请注意,我正在使用git用户名,所以,如果您正在使用gitosis或任何其他用户名,只需填写您的!

在具有root用户的控制台中执行以下命令:

 visudo 

“vi”编辑器将被打开。 添加这些行:

 Defaults:git !authenticate git ALL=(www-data) ALL 

结果文件(在“vi”编辑器中通过调用“visudo”打开)应该如下所示:

 # /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 

然后按CTRL + O保存文件,然后按Enter接受文件名(bla bla bla),然后按CTRL + Xclosures“vi”编辑器。

瞧! 现在git用户可以执行www-data用户的命令:

 sudo -u www-data git pull origin master