How to deploy your static Hugo site to Hetzner (Makefile & SSH pubkey authentication)
This this unnessesarily hard to figure out. I didn’t want to use unencrypted ftp. And Hetzner Webhosting doesn’t support scp
so I had to stick with sftp
and its quirks. If you know a better way than this, let me know.
First, you need to add your public SSH key to the hetzner webspace config at https://konsoleh.hetzner.com/logindata.php:
Second, add a Makefile
to your hugo project root:
# Makefile for Hugo website
# Default target
all: build
# Build the Hugo site
build:
hugo
# Deploy the site to Hetzner via FTP
deploy: build
@echo "Deploying to Hetzner via SFTP..."
cd public && \
echo "put -r ." | \
sftp -i ~/.ssh/id_rsa johndoe@www123.your-server.de:/public_html/jtheuer.de/
# Clean the public directory
clean:
rm -rf public/*
.PHONY: all build deploy clean
To deploy your page run:
$> make deploy
It should optput something like:
Start building sites …
hugo v0.146.3+extended+withdeploy darwin/amd64 BuildDate=2025-04-12T17:21:50Z VendorInfo=brew
| EN
-------------------+-----
Pages | 15
Paginator pages | 0
Non-page files | 0
Static files | 2
Processed images | 0
Aliases | 0
Cleaned | 0
Total in 19 ms
Deploying to Hetzner via SFTP...
cd public && \
echo "put -r ." | sftp -i ~/.ssh/id_rsa johndoe@www123.your-server.de:/public_html/jtheuer.de/
Connected to www123.your-server.de.
Changing to: /public_html/jtheuer.de/
sftp> put -r .
Uploading ./ to /public_html/jtheuer.de/.
Entering ./
index.html 100% 4137 192.9KB/s 00:00
Entering ./posts
test.html 100% 246KB 2.1MB/s 00:00
index.html 100% 4671 206.2KB/s 00:00
Happy deploying!