Auto-Push to GitHub via Machine User
The general steps are as follows:
- On the local machine, create a machine user and group.
- Create a corresponding github account for the machine user.
- Generate an SSH key machine user & associate the public key of the machine user to its github account.
- Assign the github account to the repository of interest.
- Clone the repository of interest, making it group writable.
- On the local machine, create a cron job under the machine user to execute the processing script.
Create Machine User and Group
On my local machine, I start by creating a user and group for the purpose of pushing data to github. I’m doing this to isolate the amount of exposure that this user has to my wider system.
1 2 3 4 5 6 7
Create a Github Account for Machine User
After having created the machine users on my local box, the next step is to create an analogous user on github.
Generate SSH Key & Assign to Github User
From the local machine, make sure that you’re logged in as the newly created machine user.
At this point, I defer to the great instructions on the Github help docs for generating an ssh key.
Assign Github Account As Collaborator to Repo of Interest
Next, I add our github user, rdi-git, as a collaborator on my repository of interest. Here is a link on the Github help docs.
Clone the Repository of Interest, add Assign Permissions
I’m creating a
/projects/ folder, in which I’ll clone my repo. I’d like to ensure that this folder, and
subsequently all repos contained within it, are associated with git group. This stackoverflow outlines the required commands.
1 2 3 4 5 6 7 8 9 10
Create the Cron Job
The repo I’ve just cloned contains the processing script I’ll be running. Our processed data will also be stored and pushed back to this repository.
I’d like to have my processing script run once every hour, on the hour. We setup the cron job by first entering crontab.
1 2 3
Here is an excerpt of the machine user’s cron jobs, with the new job added at the bottom.
1 2 3 4
We essential say, on the minute zero, of every hour, for every day, month, and weekday, run the command ‘python /path/to/script’. The tail indicates that we’re outputting both STDOUT and the ERROR log to
And there we go. If we check out the commit logs we can see that our github user, rdi-git, has been pushing every hour on the hour. Woo-hoo!