Hetzner VPS Setup
From a blank server to a secured production-ready machine. Choose how you want to set up your server.
Variables Preparation
In the commands below, you will need to substitute your values instead of the curly braces:
{username}— the name of your regular user (e.g.,dev){nickname}— a short name for the server for convenience (e.g.,hetzner-main){SERVER_IP}— the public IP address of your new server
1 Creating an SSH Key (Local)
Executed on your computer (Mac or Linux) BEFORE you connect to the server.
Copy the output of the second command (it starts with ssh-ed25519 ...). This is your public key.
2 Login as Root
Connect to the server using the password Hetzner sent to your email.
3 System Update
Updating all packages in non-interactive mode (without grub popups).
4 Creating a User with sudo
Working as root is dangerous. We create a regular user and give them administrator privileges.
5 SSH Key Deployment
We will write your public key, which you copied in Step 1, to the server.
6 Login Check
Do not close the root session! Open a new terminal window on your PC and try to log in using the key. You can only proceed after a successful login.
Check if sudo works (the system should ask for the password you set in Step 4 and output "root"):
7 Firewall (UFW)
Execute all subsequent commands as your new user (with sudo). Setting up the "deny all incoming except SSH, HTTP, and HTTPS" policy.
8 Kernel Protection (sysctl)
Applying parameters to protect against network attacks.
9 Basic Packages and Time
Accurate time is critical for logs, SSL certificates, and fail2ban.
10 Local SSH Config
Setting up a shortcut on your local PC to connect with a short command ssh {nickname} in the future.
11 Security Check
Verify that the short command from the local PC works and that the basic protections are enabled.
12 Final Lockdown
We install protection against brute force (fail2ban) and permanently disable password login and root login.