For this part III, I’m going to make a repository that will host the code for a very simple Hello World webpage. After that, I will setup SSH on GitHub repository and Linux, also I’ll set a cron task to fetch changes from the repository every day at 1am.
Repository
You can put whatever you like on the repository, but I recommend putting web content, as we’ve been working with Apache2 and web pages are useful because they can be very visual and we can immediately test if something works. Also, there are lots of web apps and this approach can be very useful for deploying web apps. As I said before, I will just show a hello world text. No fuzz.
SSH Keys
SSH Keys in GitHub allow computers to authenticate without providing user/password credentials. It is useful in environments where a user is not necessary, such as this example. To do this, I’m going to follow the instructions from GitHub. First, we generate a RSA key with the user registered on GitHub.
$ ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
After having this key generated, we’re going to add it to the ssh-agent.
$ ssh-add -K ~/.ssh/id_rsa
Finally, we need to get the generated key and save it on GitHub to use it.
To do so, we need to copy the key to the clipboard and paste it on GitHub’s configuration website. Xclip is a tool you can use to send content to the clipboard. If you do not have it installed, install it with$ sudo apt-get install xclip
. If you have installed it, now copy the key generated and paste it on GitHub.
xclip -sel clip < ~/.ssh/id_rsa.pub
Cron Task
On this cron task, I’m going to set up a script that moves to the web server directory and updates the server contents every day at 1am. The script that the cron task will run is the following:
cd ../../var/www/html/nameOfRepository/ git pull
This will allow the cron tab to navigate to that location and update the webpage.
Finally, the cron task will look like this:
0 1 * * * ./yourScript.sh