Gitosis post-receive 挂钩部署存储库时出现公钥错误
我的服务器上有 gitosis 设置,我正在尝试创建一个接收后挂钩,它将检出对远程计算机上工作目录的更改。
最初,我收到一条错误消息 cannot open /home/user/source/testing-local/.git/FETCH_HEAD: Permission returned
因此我将工作目录的 .git 文件夹的组所有权更改为 git 用户。
接下来我得到了错误主机密钥验证失败
,这让我检查哪个用户正在运行钩子,当然是git(愚蠢的我!),所以我在gitosis中为git用户设置了一个密钥gitosis 在 gitosis.conf 下运行并启用它。现在我得到了旧的权限被拒绝(公钥)。
我的接收后挂钩如下所示:
#!/bin/bash
while read oldrev newrev refname
do
if [ "$refname" == "refs/heads/master" ]; then
WORKDIR=/home/user/source/testing-local
export GIT_DIR=$WORKDIR/.git
pushd $WORKDIR >/dev/null
id
git pull --quiet >/dev/null
fi
done
id
调用只是为了检查我正在以哪个用户身份运行。
有没有更简单的方法来实现这一目标?我是否错过了设置中的一些关键内容?
I have gitosis setup on my server and I'm trying to create a post-receive hook that will checkout changes to a working directory on the remote machine.
Initially I got an error saying cannot open /home/user/source/testing-local/.git/FETCH_HEAD: Permission denied
so I changed the group ownership of the working directory's .git folder to the git user.
Following this I got the error Host key verification failed
which led me to check which user was running the hook, git of course (silly me!), so I setup a key in gitosis for the git user that gitosis is running under and enabled that in gitosis.conf. Now I'm getting the old Permission denied (publickey).
My post-receive hook looks like this:
#!/bin/bash
while read oldrev newrev refname
do
if [ "$refname" == "refs/heads/master" ]; then
WORKDIR=/home/user/source/testing-local
export GIT_DIR=$WORKDIR/.git
pushd $WORKDIR >/dev/null
id
git pull --quiet >/dev/null
fi
done
The id
call is just to check which user I'm running as.
Is there an easier way to achieve this?! Have I missed something key in my setup?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要确保执行该挂钩的 git 用户的
$HOME
环境变量的值。$HOME/.ssh
是 ssh 在握手期间查找私钥的位置。另外,请确保 gitosis 端的 ssh 目录具有正确的权限。
最后请参阅 GitHub 上的“权限被拒绝(公钥)”部分,其中重复了我上面提到的内容关于
HOME
:You need to make sure of the value of the
$HOME
environment variable for the git user executing that hook.$HOME/.ssh
is where ssh will look for the private key during the handshake.Also, make sure the ssh directory on the gitosis end has the right permissions.
Finally see the "Permission denied (publickey)" section on GitHub, which repeat what I mentioned above about the
HOME
: