Skip to content
Browse files

Fleshed out explanations in rsync deployment

Added some additional explanations and split up a couple command blocks to make things more clear to people less experienced with this kind of deployment.
  • Loading branch information...
napcs authored and bep committed Oct 3, 2019
1 parent 15f2ab2 commit 08da9387f82d75f6c987d5b8583b1e8e18140829
Showing with 31 additions and 11 deletions.
  1. +31 −11 content/en/hosting-and-deployment/
@@ -4,7 +4,7 @@ linktitle: Deployment with Rsync
description: If you have access to your web host with SSH, you can use a simple rsync one-liner to incrementally deploy your entire Hugo website.
date: 2017-02-01
publishdate: 2017-02-01
lastmod: 2017-02-01
lastmod: 2019-10-03
categories: [hosting and deployment]
keywords: [rsync,deployment]
authors: [Adrien Poupin]
@@ -22,6 +22,7 @@ notesforauthors:

## Assumptions

* A web host running a web server. This could be a shared hosting environment or a VPS.
* Access to your web host with SSH
* A functional static website built with Hugo

@@ -31,23 +32,35 @@ The spoiler is that you can deploy your entire website with a command that looks
hugo && rsync -avz --delete public/

As you will see, we put it in a shell script file, which makes building and deployment as easy as executing `./deploy`.
As you will see, we'll put this command in a shell script file, which makes building and deployment as easy as executing `./deploy`.

## Install SSH Key
## Copy Your SSH Key to your Host

If it is not done yet, we will make an automated way to SSH to your server. If you have already installed an SSH key, switch to the next section.
To make logging in to your server more secure and less interactive, you can upload your SSH key. If you have already installed your SSH key to your server, you can move on to the next section.

First, install the ssh client. On Debian/Ubuntu/derivates, use the following command:

{{< code file="" >}}
sudo apt-get install openssh-client
{{< /code >}}

Then generate your ssh key by entering the following commands:
Then generate your ssh key. First, create the `.ssh` directory in your home directory if it doesn't exist:

~$ cd && mkdir .ssh & cd .ssh

Next, execute this command to generate a new keypair called `rsa_id`:

~/.ssh/$ ssh-keygen -t rsa -q -C "For SSH" -f rsa_id

You'll be prompted for a passphrase, which is an extra layer of protection. Enter the passphrase you'd like to use, and then enter it again when prompted, or leave it blank if you don't want to have a passphrase. Not using a passphrase will let you transfer files non-interactively, as you won't be prompted for a password when you log in, but it is slightly less secure.

To make logging in easier, add a definition for your web host to the file `~/.ssh/config` with the following command, replacing `HOST` with the IP address or hostname of your web host, and `USER` with the username you use to log in to your web host when transfering files:

~/.ssh/$ cat >> config <<EOF
Hostname HOST
@@ -57,7 +70,7 @@ Host HOST

Don't forget to replace the `HOST` and `USER` values with your own ones. Then copy your ssh public key to the remote server:
Then copy your ssh public key to the remote server with the `ssh-copy-id` command:

~/.ssh/$ ssh-copy-id -i
@@ -70,23 +83,23 @@ Now you can easily connect to the remote server:
Enter passphrase for key '/home/mylogin/.ssh/rsa_id':

And you've done it!
Now that you can log in with your SSH key, let's create a script to automate deployment of your Hugo site.

## Shell Script

We will put the first command in a script at the root of your Hugo tree:
Create a new script called `deploy` the root of your Hugo tree:

~/websites/$ editor deploy

Here you put the following content. Replace the `USER`, `HOST`, and `DIR` values with your own:
Add the following content. Replace the `USER`, `HOST`, and `DIR` values with your own values:

DIR=my/directory/to/ # might sometimes be empty!
DIR=my/directory/to/ # the directory where your web site files should go
hugo && rsync -avz --delete public/ ${USER}@${HOST}:~/${DIR}
@@ -105,6 +118,11 @@ Now you only have to enter the following command to deploy and update your websi

~/websites/$ ./deploy

Your site builds and deploys:

Started building sites ...
Built site for language en:
0 draft content
@@ -135,3 +153,5 @@ tarifs-contact/index.html
sent 9,550 bytes received 1,708 bytes 7,505.33 bytes/sec
total size is 966,557 speedup is 85.86

You can incorporate other proprocessing tasks into this deployment script as well.

0 comments on commit 08da938

Please sign in to comment.
You can’t perform that action at this time.