Saturday, February 5, 2022

[SOLVED] GitHub - Using multiple deploy keys on a single server

Issue

Background

I have a system where when I push changes to my Repository, A web hook sends a request to my site which runs a bash script to pull the changes and copy any updated files.

I added a second repository with its own deploy key but after doing so i was getting a permission denied error when trying to pull changes.

Question

Is there a way to use 2 deploy key's on the same server?

Environment Details

  • Site uses Laravel 5.6, Symfony used to run shell script
  • Git 1.7
  • Go Daddy web hosting (Basic Linux one)

Notes

  • Script just runs git pull command
  • Error given is " Permission denied (publickey) "
  • SHH is used as a deploy key so only read access, there is one other project also using a deploy key on the same server

Thank you in advance for you help! Any other suggestions are welcome!

Edit #1

Edited post to reflect true problem as it was different to what I though (Feel free to revert if this is bad practice), please see answer below for details and solution


Solution

What i though was an issue with authentication what actually an issue with the git service not knowing which ssh key to use as i had multiple on the server.

The solution was to use a config file in the .ssh folder and assign alias to specify which ssh key to use for git operations in separate repositories.

Solution is here: Gist with solution

This gist explains the general idea, it suggests using sub-domains however a comment further down uses alias which seems neater.

I have now resolved the issue and the system is working fine with a read-only, passphrase-less deploy key.



Answered By - HarmanU
Answer Checked By - David Goodson (WPSolving Volunteer)