Current revision updated by vtopping3 on
Originally created by vtopping3 on

Learn how to connect a repository on github.gatech.edu to a vhost on one of our servers (requires at least version 5 of OpenSSH on our server).

Make SSH Keys on Server

  1. On your server, become the superuser (sudo su).
  2. Become the apache user (su -s /bin/bash - apache).
    • As the apache user, change to the home directory (cd ~)
    • Find where that home directory is located (pwd) (example: /usr/share/httpd)
  3. Go back to root user by typing command (exit).
  4. Create a folder in which to store SSH keys (mkdir /usr/share/httpd/.ssh).
  5. Create an SSH key pair on your server in the (/usr/share/httpd/.ssh) .ssh directory (ssh-keygen -b 4096 -t rsa), and name the key for the virtual host (example: /usr/share/httpd/.ssh/support). Don't enter passwords just hit enter both times.
  6. Create a config file (touch /usr/share/httpd/.ssh/config) and add this code inside it (only final line needed if only a single virtualhost on this VM):

    # support.cc
    Host support
    HostName github.gatech.edu
    PreferredAuthentications publickey
    IdentityFile /usr/share/httpd/.ssh/support
  7. Change the .ssh folder permissions (chmod 700 /usr/share/httpd/.ssh).
  8. Change the .ssh folder ownership for use by apache (chown -R apache:apache /usr/share/httpd/.ssh).
  9. Change ownership of the already-existing vhost's folder for use by apache (chown -R apache:apache /var/www/vhosts/support.cc.gatech.edu) or if not multisite (chown -R apache:apache /var/www/html).
  10. You may need to restart apache after changing the .ssh config. (systemctl restart httpd)
  11. Add your key: ssh-add /usr/share/httpd/.ssh/support

    You might need to start ssh-agent before you run the ssh-add command:

    eval `ssh-agent -s`
    ssh-add
  12. Copy the contents of the public key into your Text Editor of choice (cat /usr/share/httpd/.ssh/support.pub).

Add Deploy Key on Github

  1. Create your private repo on github.gatech.edu, under the appropriate departmental Team (example: https://github.gatech.edu/CC-TSO-WebDev). Do not add any files (not even a README).
  2. Within your repo, click the Settings tab.
  3. Choose "Deploy keys" in the left side menu, and click on "Add deploy key"
  4. Give a descriptive title, like "Scouter server public key".
  5. Paste the public key you copied from your server into the "Key" area.
    • If this is your initial copying of the repo from the server TO github, check "Allow write access", so that you can push to this github repo from your server.
    • If you already have the initial copy of your files pulled from the server, you need to delete the old key and make a new one that does NOT allow write access (to improve our security setup).
  6. Click "Add key".

Connect your Server to Github

  1. Make sure git is running (git --version).
  2. Become the apache user (su -s /bin/bash - apache).

Existing Server Repository

If this vhost on your server already has a git repo initialized, follow these steps:

  1. Change to your vhost's or html folder (cd /var/www/vhosts/support.cc.gatech.edu) or html folder (cd /var/www/html).
  2. Use ssh to add the github repo as its origin, including the "Host" you created in the .ssh/config file as the url so that the server uses the correct ssh key to connect (git remote add origin git@support:CC-TSO-WebDev/support.git). [if only single virtualhost on VM, use git@github.gatech.edu:CC-TSO-WebDev/support.git]
  3. Push your server's repo to github (git push -u origin master).
  4. Check the repo on github to make sure you see the commits from your server.

New Server Repository

If this vhost on your server does not yet have a git repo initialized, follow these steps:

  1. Change to the directory above your vhost (cd /var/www/vhosts).
  2. Use ssh to copy the repo from to your server, including the "Host" you created in the .ssh/config file as the url so that the server uses the correct ssh key to connect (git clone git@support:CC-TSO-WebDev/support.git support.cc.gatech.edu).[if only single virtualhost on VM, use git@github.gatech.edu:CC-TSO-WebDev/support.git support.cc.gatech.edu]
  3. Change to your vhost's folder (cd /var/www/vhosts/support.cc.gatech.edu).
  4. Check the repo on your server to make sure you see the commits from github (git log -n 1).

Firewalls for Github.com

You may need to open the firewalls to allow an off-campus connection to github.com.

Customize .gitignore file

For a Drupal 7 site, add these lines to the repo's .gitignore file (as they should not be version controlled):

  • sites/*/files
  • sites/*/private
  • sites/*/settings.php

Configure protected master branch on Github (Under construction section)

Since you will be connecting the repo to a Production site, you need to protect the master branch on github, so that all changes pushed to it must go through an approval process before being merged into the master/production branch.

Set crontab to do a git pull as the apache user (Under construction section)

Example (run every 4 hours):
0 */4 * * * cd /var/www/vhosts/support.cc.gatech.edu && git pull origin master >> /dev/null

Change File Permissions (Under construction section)

Often, the file and directory permissions on the server differ from your local development environment. You will need a cron job or automatic git-accompanying command so that, whenever it pulls updates from the remote repository, files and directories receive the correct ownership and permissions for the server.

For a Drupal 7 site, the defaults should be:

  • user and group = apache:apache
  • most directories = 755
  • most files = 644
  • not version controlled, so set it once and forget it:
    • settings.php file = 444
    • /sites/*/files = 777 (directory)
    • /sites/*/files/* = 666 (files)

Repository default settings

Details will go here.

Identifier Categories
Specific categories