-->

后收到钩权限被拒绝“无法创建文件”错误(post-receive hook permission d

2019-06-25 18:36发布

刚刚gitolite安装在我的网络服务器和我试图让一个post-receive钩,可以指向的git dir中apache的方向。

这就是我的post-receive钩的样子。 得到了来自该脚本使用Git来管理网站 。

#!/bin/sh
echo "post-receive example.com triggered"
GIT_WORK_TREE=/srv/sites/example.com/public git checkout -f

我也试过:

#!/bin/sh
echo "post-receive example.com triggered"
unset GIT_INDEX_FILE
export GIT_WORK_TREE=/srv/sites/example.com/public
export GIT_DIR=/home/git/repositories/example.com.git
git checkout -f

这是错误的反应我是来自找回git push origin master从我的本地工作站。 这些都是从我的资料库中的文件。

remote: post-receive example.com triggered
remote: error: unable to create file .htaccess (Permission denied)
remote: error: unable to create file .tm_sync.config (Permission denied)
remote: fatal: cannot create directory at 'application': Permission denied

独立脚本错误

remote: sudo: no tty present and no askpass program specified
remote: Sorry, try again.
remote: sudo: no tty present and no askpass program specified
remote: Sorry, try again.
remote: sudo: no tty present and no askpass program specified
remote: Sorry, try again.
remote: sudo: 3 incorrect password attempts

更新:

git@vannevar:~$ sudo -l
Matching Defaults entries for git on this host:
    env_reset, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin

User git may run the following commands on this host:
    (root) NOPASSWD: /usr/local/sbin/prgetsimpleappscom
git@vannevar:~$ /usr/local/sbin/prgetsimpleappscom
-su: /usr/local/sbin/prgetsimpleappscom: Permission denied
git@vannevar:~$ sh /usr/local/sbin/prgetsimpleappscom
post-receive getsimpleapps.com triggered
error: unable to unlink old 'application/config/development/database.php' (Permission denied)
error: unable to unlink old 'application/config/production/database.php' (Permission denied)
error: unable to unlink old 'application/config/quickbooks.php' (Permission denied)
git@vannevar:~$ sudo sh /usr/local/sbin/prgetsimpleappscom
[sudo] password for git: 
Sorry, user git is not allowed to execute '/bin/sh /usr/local/sbin/prgetsimpleappscom' as root on vannevar.
git@vannevar:~$ sudo /usr/local/sbin/prgetsimpleappscom
[sudo] password for git: 
sudo: /usr/local/sbin/prgetsimpleappscom: command not found
git@vannevar:~$ nano /usr/local/sbin/prgetsimpleappscom
git@vannevar:~$ 

Answer 1:

这是我如何得到它的工作:

更改post-receive到:

sudo sh /usr/local/sbin/prgetsimpleappscom

改变sudoersvisudo

git ALL = (root) NOPASSWD: /usr/local/sbin/prgetsimpleappscom
git ALL = (root) NOPASSWD: /bin/sh
git ALL = (root) NOPASSWD: /bin/sh /usr/local/sbin/prgetsimpleappscom

确认visudo工作

git@vannevar:~$ sudo -l
Matching Defaults entries for git on this host:
    env_reset, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin

User git may run the following commands on this host:
    (root) NOPASSWD: /usr/local/sbin/prgetsimpleappscom
    (root) NOPASSWD: /bin/sh
    (root) NOPASSWD: /bin/sh /usr/local/sbin/prgetsimpleappscom

跑:

sudo sh /usr/local/sbin/prgetsimpleappscom
post-receive getsimpleapps.com triggered

和:

$ git push origin master
remote: post-receive getsimpleapps.com triggered


文章来源: post-receive hook permission denied “unable to create file” error