开发者

Git hook and ssh Agent Forwarding

开发者 https://www.devze.com 2023-04-13 01:41 出处:网络
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 ser

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 tha开发者_高级运维nks 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.

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.

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 :)

0

精彩评论

暂无评论...
验证码 换一张
取 消