Git hook 和 ssh 代理转发

发布于 2024-12-09 18:08:53 字数 408 浏览 0 评论 0原文

我有一个带有 git 存储库的远程开发服务器。

当我从本地计算机推送到此开发服务器时,它会运行 git hook after-receive 将开发分支推送到 Heroku 临时服务器上。

我的身份被转发到开发服务器,这是我的 ~/.ssh/config

Host *
  User myuser
  ConnectTimeout 15
  ServerAliveInterval 45
  ForwardAgent yes
  IdentityFile ~/.ssh/id_rsa

我怎样才能让它被钩子使用来部署在heroku上?

目前它不使用转发的代理,而是使用开发服务器 ssh 身份。我们希望避免服务器上的 ssh 密钥,因为很多人都在推动。

非常感谢您的想法。

I've got a remote development server with a git repository.

When I push from my local machine to this dev server it runs the git hook after-receive to push the develop branch on a heroku staging server.

My identity is forwarded to the development server, here is my ~/.ssh/config

Host *
  User myuser
  ConnectTimeout 15
  ServerAliveInterval 45
  ForwardAgent yes
  IdentityFile ~/.ssh/id_rsa

How can I make it used by the hook to deploy on heroku ?

For the moment it does not use the agent forwarded but uses the development server ssh identity. We want to avoid the ssh key on the server as many person are pushing.

Many thanks for your ideas.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

﹏雨一样淡蓝的深情 2024-12-16 18:08:53

因此,我将其添加到 shell 会话的配置文件中(例如配置文件或 bashrc conf),它就完成了这项工作。

if [ ! -d /tmp/501 ]; then
  mkdir /tmp/501
  ssh-agent -a /tmp/501/ssh-agent.socket
fi

SSH_AUTH_SOCK=/tmp/501/ssh-agent.socket
export SSH_AUTH_SOCK
ssh-add ~/.ssh/id_rsa

希望这会对某人有所帮助。

So I added this in the profile of my shell session (profile or bashrc conf for example) and it does the job.

if [ ! -d /tmp/501 ]; then
  mkdir /tmp/501
  ssh-agent -a /tmp/501/ssh-agent.socket
fi

SSH_AUTH_SOCK=/tmp/501/ssh-agent.socket
export SSH_AUTH_SOCK
ssh-add ~/.ssh/id_rsa

Hopefully that will help someone.

复古式 2024-12-16 18:08:53

由于您使用用户 myuser 连接到开发服务器,因此 git hook 也应该以 myuser 身份运行。

如果您尚未为用户 myuser 创建用于从您的开发服务器连接到 heroku 临时服务器的 ssh 密钥对,您需要执行以下操作那。

<Login to your development server as myuser>
ssh-keygen -t rsa
<Upload the public key onto your heroku server's authorized_keys file>

您需要在开发服务器上为用户 myuser 创建一个类似的 ~/.ssh/config,挂钩可以使用它来连接到登台服务器。

为了确认您可以从开发服务器尝试此命令,看看它是否可以登录登台服务器:

ssh heroku-staging-server

这应该是全部:)

Since you're connecting to the development server with your user myuser, the git hook should also be running as myuser.

If you've not already created ssh-keypairs for connecting to your heroku staging server from your development server for user myuser, you need to do that.

<Login to your development server as myuser>
ssh-keygen -t rsa
<Upload the public key onto your heroku server's authorized_keys file>

You need to create a similar ~/.ssh/config on your development server for the user myuser that can be used by the hook to connect to the staging server.

And to confirm you can try this command from your development server to see if it can login into the staging server:

ssh heroku-staging-server

That should be all :)

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