Skip to content

Instantly share code, notes, and snippets.

@miklobit
Forked from holmberd/deploy-keys.md
Created February 17, 2020 15:11
Show Gist options
  • Save miklobit/a241f50a12ecec27434efc25d46445d9 to your computer and use it in GitHub Desktop.
Save miklobit/a241f50a12ecec27434efc25d46445d9 to your computer and use it in GitHub Desktop.
Setup GitHub repository SSH deploy keys

Setup GitHub repository SSH deploy keys

  1. Create GitHub repository in github and save the SSH repository url

  2. Init git on server in code directory

  • git init
  1. Create SSH keys on the server
  • ssh-keygen -t rsa -b 4096 -C your@email.here
  • Rename the key that doesn't end with .pub to repo-name.deploy.pem
  • Save .pub file content to your local client for use later
  • Move .pem key to ~/.ssh/ or suitable location
  • Change key file permission: sudo chmod 400 repo-name.deploy.pem
  1. Create ssh-config file
  • Navigate to ~/.ssh and touch config set permission sudo chmod 644 config
  • Add entry in config file
Host gitreponame
Hostname github.com
IdentityFile ~/.ssh/repo-name.deploy.pem
  1. Add the content from the public key file i.e. .pub to your github repository, settings > deploy keys > Add deploy keys

  2. Set the remote git repository url on the server for the initalized git repo

  • git remote add origin git@gitreponame:organization-name/repo-name.git or if already existing git remote set-url origin git@gitreponame:organization-name/repo-name.git
  • test with: git remote -v
  1. Add files to commit and push them to the master branch
  • git add .
  • git commit -m 'root commit'
  • git push -u origin master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment