简体   繁体   English

Git钩和SSH代理转发

[英]Git hook and ssh Agent Forwarding

I've got a remote development server with a git repository. 我有一个带有git存储库的远程开发服务器。

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. 当我从本地计算机推送到此开发服务器时,它将在接收后运行git hook,以将开发分支推送到heroku登台服务器上。

My identity is forwarded to the development server, here is my ~/.ssh/config 我的身份转发到开发服务器,这是我的〜/ .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 ? 我如何使它被钩子使用以部署在heroku上?

For the moment it does not use the agent forwarded but uses the development server ssh identity. 目前,它不使用转发的代理,而是使用开发服务器的ssh身份。 We want to avoid the ssh key on the server as many person are pushing. 我们希望避免许多人在推动服务器时使用ssh密钥。

Many thanks for your ideas. 非常感谢您的想法。

So I added this in the profile of my shell session (profile or bashrc conf for example) and it does the job. 因此,我将其添加到了我的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

Hopefully that will help someone. 希望能对某人有所帮助。

Since you're connecting to the development server with your user myuser , the git hook should also be running as myuser . 由于您使用用户myuser连接到开发服务器,因此git钩子也应该以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. 如果尚未为用户myuser创建用于从开发服务器连接到heroku登台服务器的 ssh-keypair,则需要执行此操作。

<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. 您需要在开发服务器上为用户myuser创建一个类似的〜/ .ssh / config,该钩子可以使用它来连接到登台服务器。

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 :) 那应该是全部:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM