Deploying Private Repos Automatically with Github

November 22, 2013

I posted recently about how I used Github webhooks to set up automated deployment scripts for the Entertainment Weekly and TechCrunch responsive redesign projects. In that article, I pointed out that there are “some tricky bits” to deal with if the repo is private on Github.

A couple people have contacted me to ask for help with the tricky bits (security related stuff). As I tried to type up my response to them, I realized that it’s really freaking hard to describe how to deal with the security stuff.


I present to you here an alternate approach that attempts to strike a reasonable balance between simplicity, convenience, and security. It does require that you use the command line, but I try to keep the steps to an absolute minimum.

Related Links

Step-by-Step Instructions

In the screencast, I depart a bit from the step-by-step instructions below so stick with what I said in the video. I have left the text below merely as a reference. PLMK if you have questions.

Create SSH Keys On Your Server

  1. Launch Terminal and ssh into your server (replace with your info, of course)

    ssh root@


  2. Check for ssh keys

    cd ~/.ssh


  3. If need be, generate public/private key pair (make sure to leave passphrase blank)

    ssh-keygen -t rsa -C ""

    Enter file in which to save the key (/Users/you/.ssh/id_rsa): [Press enter]

    Enter passphrase (empty for no passphrase): [Press enter]

    Enter same passphrase again: [Press enter]

  4. Copy the contents of the .pub file that was created


  5. Leave Terminal as is (you'll be coming back in a sec)

Add SSH Key To Github

  1. Launch a web browser and log into your Github account
  2. Navigate to Github > Account Settings > SSH Keys
  3. Click the Add SSH Key button
  4. Give your key a title and paste in the contents of the public key file
  5. Click the Add Key button to save your changes

Test SSH Connection

  1. Go back to Terminal
  2. Confirm that you are still ssh'd into your web server (you should be)
  3. Test your ssh connection to Github by entering the following command:

    ssh -T

  4. You might see an authenticity warning like this:

    The authenticity of host ' (' can't be established...

    Don't worry, this is supposed to happen. Enter "yes" to continue.

  5. Hopefully, you'll see this message:

    Hi [username]! You've successfully authenticated, but GitHub does not provide shell access.

Set Up A Cronjob

  1. Launch Terminal and ssh into your server, if you're not logged in already
  2. Enter the following command:

    crontab -e

  3. Add the following line at the end of the file:

    * * * * * cd /path/to/your/repo/directory/ && git pull

Test Your Setup

  1. Launch a web browser and log into your Github account
  2. Navigate to the repo in question
  3. Edit one of the files
  4. Wait a minute
  5. In another browser tab, load your site
  6. You should see your change on the site

If you are a software developer who is interested in breaking the feast/famine business cycle, attracting better clients, moving away from hourly billing, and getting paid as an expert instead of a laborer, you might want to check out my business coaching for software developers.