The Hugo static file generator can be installed on Linux, Windows, macOS, and BSD computers.

Using Hugo’s built-in web server and locally configured Decap content management system, you can add and edit your site’s content using an easy-to-use web-based UI editor that includes rich text editing, live preview, and drag-and-drop media uploading.

With its advanced templating system and fast asset pipelines, Hugo renders a complete site in seconds.

Since Hugo creates static websites, you can host your Hugo website on virtually any host by simply transferring the generated files to it.

If you have access to your web host via SSH, you can use the rsync command to deploy your Hugo website securely and quickly.


1. Publishing process from Windows 10/11

1.1. Installing Git

Install Git for Windows, which allows you to run the Rsync command using Git Bash.

1.2. Installing Rsync and its dependencies

Go to https://repo.msys2.org/msys/x86_64/ , download the latest packages:

  1. rsync ( rsync-3.2.7-2-x86_64.pkg.tar.zst )
  2. libxxhash ( libxxhash-0.8.2-1-x86_64.pkg.tar.zst )
  3. liblz4 ( liblz4-1.9.4-1-x86_64.pkg.tar.zst )
  4. libzstd ( libzstd-1.5.5-1-x86_64.pkg.tar.zst )
  5. libopenssl ( libopenssl-3.2.0-1-x86_64.pkg.tar.zst )

Download and install the archiver https://github.com/mcmilk/7-Zip-zstd/releases (for example 7z22.01-zstd-x64.exe). Run 7zFM.exe (usually located in the folder C:\Program Files\7-Zip-Zstandard) and unpack the downloaded archives into the Git folder, for example:

  • \rsync-3.2.7-2\usr\bin → C:\Program Files\Git\usr\bin
  • \rsync-3.2.7-2\usr\lib → C:\Program Files\Git\usr\lib
  • \rsync-3.2.7-2\usr\share → C:\Program Files\Git\usr\share

and similarly the remaining archives.

1.3. Copy your SSH key to your host

To make logging into your server more secure, you can upload your SSH key. If you have already installed your SSH key on your server, you can skip to the next section.

Run git-bash.exe (usually located in C:\Program Files\Git ) and run this command to generate a new key pair named rsa_id:

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

You will be prompted for a passphrase, which is an extra layer of security. Enter the passphrase you would like to use, then enter it again when prompted, or leave it blank if you do not want to use a passphrase. If you do not use a passphrase, you will not be prompted for a password when logging in, but it is slightly less secure.

As a result, two files with a private and public key (rsa_id and rsa_id.pub) will be created in your folder (for example C:\Users\USER_NAME\.ssh).

To make logging in easier, add your web host definition to your ~/.ssh/config file using the following commands, replacing USER_NAME with your current Windows user name, HOST with your current IP address, and USER with the user name you use to log into your web host when transferring files:

$ cd /c/Users/USER_NAME/.ssh

~/.ssh/$ cat >> config <<EOF
Host HOST
Hostname HOST
Port 22
User USER
IdentityFile ~/.ssh/rsa_id
EOF

After running the commands, you should have a config file in your Windows .ssh folder (usually located at C:\Users\user_name\.ssh\config) with the following contents:

Host HOST Hostname HOST Port 22 User USER IdentityFile ~/.ssh/rsa_id

Warning

Don’t forget to enable SSH access on your web hosting. How to enable SSH access on the popular Timeweb hosting, see here.

Next, go to the .ssl folder and copy your SSH public key to the remote server using the ssh-copy-id commands, replacing user_name with the current Windows user name, HOST with its IP address, and USER with the username you use to log into your web host when transferring files:

$ cd /c/Users/user_name/.ssh
$ ssh-copy-id -i rsa_id.pub USER@HOST

Now you can easily connect to the remote server:

$ ssh USER@HOST
Enter passphrase for key '/home/mylogin/.ssh/rsa_id':

Close the current git-bash connection.

1.4. Create a script to start the publishing process

Run the git-bash.exe file (usually located in the C:\Program Files\Git folder).

Create a new script called deploy in the root of your Hugo site tree (for example: D:\Hugo\Sites\webpractica):

$ cd /d/Hugo/Sites/webpractica

/d/Hugo/Sites/webpractica (main)
$ cat >> deploy <<EOF
#!/bin/sh
hugo --gc --minify && rsync -avz --delete public/ USER@HOST:~/webpractica/public_html
exit 0
EOF

Parameters used:

-a - data archiving support is activated; -v - the synchronization process is displayed on the screen; -z - file compression occurs when transferring to a remote server;

--delete - Deleting files during synchronization. By default, the destination directory stores all files previously copied there. Even those that the user has long since deleted from the working disk because they were no longer needed. Therefore, it is recommended to at least periodically delete unnecessary data, rather than reduce the size of the directory with the backup copy of the information.

Info

For more information on Rsync settings and examples read here

Make deploy executable:

/d/Hugo/Sites/webpractica (main)
$ chmod +x deploy

Create deploy.bat to run deploy script under Windows

/d/Hugo/Sites/webpractica (main)
$ cat >> deploy.bat <<EOF
"C:\Program Files\Git\git-bash.exe" "deploy"
EOF

Close the current git-bash connection.

1.5. Publishing a local Hugo site to a web host

Run the deploy.bat file from the root directory of your Hugo site

2. Publishing process from Linux (Debian)

A detailed description can be found on the official Hugo website here.