Answers:
请注意,我使用的是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 + X关闭“ vi”编辑器。
瞧!现在git用户可以以www-data用户身份执行命令:
sudo -u www-data git pull origin master