Skip to content

Instantly share code, notes, and snippets.

@agalea91
Created June 24, 2020 15:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save agalea91/ac3f770dadec9917d8fa1414ee48d24d to your computer and use it in GitHub Desktop.
Save agalea91/ac3f770dadec9917d8fa1414ee48d24d to your computer and use it in GitHub Desktop.
How to setup a deploy key for repo on shared server environment

GitHub Deploy Key Setup

  1. Generate key
ssh-keygen
...
cp ./key-name* ~/.ssh
  1. Go to GitHub repo and add key-name.pub

  2. Clone repo using trick from this stackoverflow thread

ssh-agent bash -c 'ssh-add ~/.ssh/key-name; git clone git@github.com:user/proj-name.git'
  1. Open ~/.ssh/config and add a block like this:
Host github-proj-name
HostName github.com
IdentityFile ~/.ssh/key-name
  1. Finally, open .git/config in your new repo and change the hostname in the git connection string like this:
git@github-proj-name:user/proj-name.git

Now you will be able to push/pull without password authentication.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment