How to Publish Your Jekyll Site with SCP

In this article, we’ll show you how you can automate your publishing process with secure copy (SCP). In the customizing Jekyll article we learned about how you can change the base directory of your site. This means you will be building your site into a specific directory, which is going to be important later.

Then, we can create a simple script that will grab your base directory and copy it to your server with minimal effort on your part.

SSH Access

In order for this process to work easily and quickly, you will want to set up an SSH key on your computer and then add the key to your server. Why? SCP uses the SSH protocol to transfer files to your server. This means you will require a password in order to make our script run. With an SSH key, however, we can skip the password phase and transfer files directly. This is also considered a more secure way to control access to your server.

Change your Jekyll Build Base Directory

As mentioned above, you will want to customize your Jekyll installation to “build” your site into a directory called public_html. This will work better with your InMotion Hosting cPanel server, which has already chosen the public_html directory as the document root.

Creating the SCP Script

Now that you have added the SSH key to your server, we can create the SCP script. This kind of scripting is very specific and may differ based on individual use cases. This is why I’ll emphasize that this is merely one way among many to accomplish the same goal. You might take this as inspiration to create your own script, or, what we’ve provided here may be sufficient for your needs.

What we’re going to do is create an executable script that will transfer our public_html directory in our Jekyll site to our server location.

The steps must be completed on your local computer, not your server.

  1. Create a new file on your computer called (you may name it anything you want, this is only an example)
  2. Open the file for editing with your text editor
  3. Add the following code into your file:
     #!/bin/bash scp -rp /path/to/jekyll/public_html

    Making sure that you update the path to your Jekyll site and substitute the server information for your own

  4. Open your terminal application
  5. Use the cd command to change into the directory where you created the file (if you created it in your home folder, you may already be in the right place)
  6. Use the following command to make the file executable:
     sudo chmod +x 
  7. Run the executable file by adding a period and forward slash before it:

Now your command should automatically use SCP to transfer the files to your server without your having to log into your server. Every time you make changes to your site, use jekyll build to build the site and your custom script to transfer the files.

Leave a Reply