Gitosis post-receive 挂钩部署存储库时出现公钥错误

发布于 2024-10-27 19:19:16 字数 762 浏览 0 评论 0原文

我的服务器上有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

愚人国度 2024-11-03 19:19:16

您需要确保执行该挂钩的 git 用户的 $HOME 环境变量的值。

$HOME/.ssh 是 ssh 在握手期间查找私钥的位置。
另外,请确保 gitosis 端的 ssh 目录具有正确的权限

server$ chmod go-w ~/
server$ chmod 700 ~/.ssh
server$ chmod 600 ~/.ssh/authorized_keys

最后请参阅 GitHub 上的“权限被拒绝(公钥)”部分,其中重复了我上面提到的内容关于HOME

这通常是由于 ssh 找不到您的密钥造成的。
确保您的密钥位于默认位置 ~/.ssh

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.

server$ chmod go-w ~/
server$ chmod 700 ~/.ssh
server$ chmod 600 ~/.ssh/authorized_keys

Finally see the "Permission denied (publickey)" section on GitHub, which repeat what I mentioned above about the HOME:

This is usually caused when ssh cannot find your keys.
Make sure your key is in the default location, ~/.ssh.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文