- Why does a new VPS need hardening?A freshly created VPS is reachable from the whole internet within a minute, and automated scanners find new addresses quickly.
- What should you do in the first hour?Install all pending package updates, then reboot if the kernel changed.
- How do you secure SSH?SSH is the front door.
Why does a new VPS need hardening?
A freshly created VPS is reachable from the whole internet within a minute, and automated scanners find new addresses quickly. Logs on a new server often show login attempts within the first hour. Default settings are designed to get you started, not to resist attack. Hardening reduces what an attacker can reach and what they can do if they get in.
The good news is that a short routine covers most of the risk. This checklist assumes a Linux server such as Ubuntu or Debian. Commands vary slightly by distribution, so use your provider’s and distribution’s documentation for exact syntax.
What should you do in the first hour?
- Update everything
Install all pending package updates, then reboot if the kernel changed.
- Create a normal user
Give it sudo rights and stop using root for daily work.
- Set up SSH keys
Add your public key and test the login before changing anything else.
- Turn on a firewall
Allow only the ports you need, such as SSH, HTTP and HTTPS.
- Enable automatic security updates
So fixes arrive without you remembering.
- Take a snapshot and a backup
Record a clean starting point.
How do you secure SSH?
SSH is the front door. Use key-based authentication, which is far harder to guess than any password. Generate a key pair on your own computer, copy the public key to the server, test that you can log in with it, and only then turn off password authentication and direct root login in the SSH daemon configuration. Always keep a second session open while you change SSH settings, so a mistake does not lock you out.
Changing the default port is optional and gives little real protection, but it reduces log noise. A tool that blocks repeated failed logins adds another layer. Our guide to what SSH access is explains the basics, and the OpenSSH manual lists every setting.
How do you set up a firewall?
A host firewall allows only the connections you want. On Ubuntu, the Uncomplicated Firewall (UFW) is a simple front end: allow SSH first so you do not cut yourself off, allow the web ports if you run a site, then enable it. Many providers also offer a network-level firewall in their control panel, which blocks traffic before it reaches the server; using both is a good practice.
Review open ports from time to time. Services you installed and forgot, such as a database listening on a public address, are a common cause of breaches. Databases should listen only on the local address unless you have a reason and a firewall rule to allow others.
How do you keep the system updated?
Most attacks use known flaws that have fixes available. Turn on automatic security updates for the operating system, and schedule time to update application software, such as your CMS and its plugins, language runtimes and containers. Know which versions you run and when they stop being supported. Our guides on PHP versions and WordPress requirements show how to check.
When a kernel update needs a reboot, plan it, or use a live patching service if your distribution offers one.
What else should you secure?
- Run each service as its own unprivileged user.
- Use HTTPS with a free certificate; see what an SSL certificate is.
- Put a web application firewall or a CDN in front of public sites; see do you need Cloudflare?.
- Consider DDoS protection if you are a likely target.
- Remove software you do not use.
- Store secrets in environment files or a secrets manager, never in the code repository.
How do you back up and monitor?
Snapshots are quick and useful, but they usually live with the same provider. Add a file-and-database backup to separate storage, and test a restore, as described in website backups. Monitor uptime from outside with a free service, watch disk space and memory, and read the authentication log from time to time. Alerts that reach you at the right time are worth more than dashboards you never open.
What should you do if you think the server is compromised?
If you do not want to carry this responsibility, a managed plan moves most of it to the provider.
- Isolate it
Block traffic with the provider firewall or take a snapshot and shut it down.
- Preserve evidence
Keep logs and a disk snapshot for investigation.
- Rebuild, do not clean
Create a fresh server from a known good image and restore data from a clean backup.
- Rotate every secret
Change passwords, keys and API tokens that were on the server.
A worked example: the first hour on a new server
A developer creates a VPS at 10:00. At 10:05 they log in as root with the password the provider emailed and immediately update packages. At 10:15 they create a user, add their SSH key and test a login in a second window. At 10:25 they disable password and root login, restart the SSH service and confirm the key login still works. At 10:30 they enable the firewall, allowing only SSH, HTTP and HTTPS, and turn on automatic security updates. At 10:40 they check the authentication log and already see failed logins from several countries, all rejected. At 10:50 they take a snapshot and set up an off-server backup of the site folder and database.
An hour later the server is far safer than it was, and the owner has a clean snapshot to return to. The log lines are a reminder that the internet is probing every new address.
What should you review every month?
- Pending updates and whether any need a reboot.
- The authentication log for unusual logins.
- Open ports and running services.
- Free disk space and memory.
- Backups: do they exist, are they recent and have you restored one lately?