← All Articles

Use different keys for Git and SSH

Khash SajadiKhash Sajadi
Sep 19th 12Updated Jul 27th 17

We needed to run a capistrano recipe on a remote box so it would deploy the code on another remote box. Here is a simple schematic diagram!

Our dev box Our server Destination Server

This works if your git repository shares the same key with your server. In our case it wasn’t. We have one key to connect to the Destination Server and another one used for the git repository.

Here is a workaround for this scenario:

Write your normal cap deploy file, configured with the SSH key used for connecting to the Destination Server. That would look like this:

ssh_options[:keys] = '/keys/my_ssh_key.pub'

When it’s time to run the cap deploy on Our Server against Destination Server, we did this to make it work:

ssh-agent bash -c 'ssh-add /keys/git_key.pub; cap deploy'

Try Cloud 66 for Free, No credit card required