How to Secure a VPS: Essential Setup Checklist

Cover graphic: How to Secure a VPS: Essential Setup Checklist

Core takeaway

  • Before production work: create a non-root admin user, use SSH keys instead of password-only login, disable direct root SSH login, and open only the ports you need.
  • Keep it small and current: update the system, remove unused services, use least privilege, and keep databases and internal services off the public internet.
  • Watch it and recover it: use HTTPS with certificate renewal, monitor logs and capacity, and keep encrypted, off-site backups with tested restores.
  • Layers, not one setting: SSH keys do not replace patching, and backups do not replace a firewall.

Disclosure: con1ainer.com participates in affiliate programs. This article contains no affiliate links. See the Affiliate & Commercial Disclosure.

The 15-second version of the four things to do before anything else.

A new VPS is not secure simply because it is new.

Once a server has a public IP address, it will be seen by automated scanners, password-guessing tools, vulnerability probes, and systems searching for exposed services. Security is not a final task after deployment. It is part of deploying the server properly in the first place.

The good news is that solid VPS security does not require a pile of exotic tools. It comes down to a few disciplined habits: control who can log in, reduce what is exposed, keep software current, limit privileges, monitor the system, and maintain backups you can actually restore.

This guide covers the essentials for a Linux VPS. Exact commands differ between Ubuntu, Debian, AlmaLinux, Rocky Linux, and other distributions, but the principles remain the same.

The Short Answer

Secure a VPS by taking care of these fundamentals before you put production work on it:

  1. Create a non-root administrative user.
  2. Use SSH keys instead of password-only login.
  3. Disable direct root SSH login.
  4. Configure a firewall and allow only needed ports.
  5. Keep the operating system and packages updated.
  6. Remove unused services.
  7. Use least privilege for people, services, and applications.
  8. Keep databases and internal services off the public internet.
  9. Use HTTPS and manage certificate renewal.
  10. Monitor logs, services, capacity, and suspicious activity.
  11. Maintain encrypted, off-site backups and test restores.
  12. Separate public services from administrative access.

Security is strongest when those controls work together. SSH keys are useful, for example, but they do not replace patching. Backups matter, but they do not replace a firewall. Treat the VPS as a system with several layers rather than a single setting to turn on once and forget.

1. Create a Non-Root Admin User

Do not use root as your everyday login.

Create a separate, named administrative user and give it only the privileges needed to manage the server. On many Linux distributions, that means adding the account to the sudo group or its equivalent.

A non-root account reduces the chance that a mistake, compromised application, or stolen login session immediately has unrestricted control of the server. It also creates a clearer audit trail because server logs can show which named account carried out an administrative task.

Before making any SSH restrictions, confirm that the administrative account can log in and use sudo successfully. Keep an existing working session open while testing access from a second terminal.

2. Use SSH Keys, Not Passwords

SSH keys should be the normal way to administer a VPS. They are far stronger than password-only login and protect against the constant stream of automated password-guessing attempts aimed at public servers.

An SSH key pair consists of a private key that remains on your computer and a public key that is installed on the server. The server verifies that you hold the matching private key without asking for a reusable password over the network.

Set up key-based login for your non-root administrative user, then test it in a separate terminal before changing SSH password settings. Do not disable password authentication until you have confirmed that key-based access works.

Use a separate SSH key for each person and, where practical, for each administrative device. Protect private keys with a strong passphrase, remove public keys when access is no longer needed, and never place private keys in source repositories, shared folders, tickets, or chat messages.

3. Disable Direct Root SSH Login

Root is the most predictable account name on a Linux server, making it a permanent target for automated attacks. Once your named administrative user has been tested, disable direct root login over SSH.

In many SSH configurations, that means setting the following directive:

PermitRootLogin no

You can still perform administrative work. You simply sign in with your named account and elevate privileges deliberately with sudo when needed.

Do not make this change until your non-root user has been tested in another terminal session. A clean security setup should not require a support ticket because the only administrator has been locked out.

4. Configure a Firewall

A firewall determines which network connections can reach the VPS. A sensible baseline is to deny unsolicited inbound traffic by default, then allow only the ports and services the server actually needs.

For a typical public website, the allowed services are usually limited to:

  • SSH for administration.
  • HTTP on port 80 when needed for web traffic or certificate validation.
  • HTTPS on port 443 for encrypted web traffic.

Database ports, caches, control panels, development tools, and internal dashboards should remain closed to the public internet unless there is a specific and well-controlled reason to expose them.

Many Ubuntu and Debian systems use ufw, while RHEL-family distributions commonly use firewalld. Your VPS provider may also offer a network firewall or security-group feature. Use provider-level controls and a host firewall together where practical; each provides a useful layer of protection.

Before enforcing restrictive firewall rules, make sure the port used by your current SSH connection is explicitly allowed. Test a new login before closing your existing session.

5. Keep the System Updated

Unpatched software is one of the most common routes into a server. Operating-system updates, package updates, web-server patches, database patches, and application updates all belong in the maintenance plan.

Build a routine for applying security updates promptly, checking internet-facing services and dependencies, restarting services when needed, and recording meaningful maintenance changes.

Keep more than the operating system current. Update the web server, programming runtime, CMS, plugins, frameworks, databases, container images, and any control-panel software installed on the VPS. An up-to-date operating system does not protect an outdated application with a known flaw.

Automatic security updates can be appropriate for low-risk patches, particularly on smaller servers. They do not eliminate the need to test major version changes, application updates, or infrastructure changes before applying them to production.

6. Remove Unused Services

Every running service adds software to patch, configuration to review, logs to monitor, and a possible entry point to defend. If the VPS does not need a service, remove it or disable it.

Review listening ports, active processes, and services that start automatically at boot.

Common candidates for review include:

  • Default web servers that are no longer used.
  • Database servers that should be on a private network or another host.
  • FTP, mail, or file-sharing services enabled during testing.
  • Old application processes, development servers, and unused containers.
  • Packages installed for a one-time task and then forgotten.

Tools such as ss, systemctl, and your firewall status view can help identify what is listening and what is running. Do not remove components blindly on a production system; first understand what depends on them.

7. Use Least Privilege

Least privilege means giving users, applications, services, and automated tasks only the access they need to do their work—and no more.

That starts with not running everything as root. Web applications should normally run under dedicated service accounts. Database users should have only the permissions their application requires. Deployment accounts should not automatically have unrestricted access to all files, credentials, and services.

Apply least privilege to Linux accounts, sudo permissions, SSH keys, database roles, API keys, cloud credentials, application service accounts, scheduled tasks, backup jobs, and monitoring agents.

Use separate named accounts for separate people. Remove access when it is no longer needed. Review privileged accounts periodically, particularly after a contractor, employee, project, or device leaves the picture.

Least privilege will not prevent every incident, but it limits the damage when one account, credential, or application is compromised.

8. Protect Databases and Internal Services

Databases should not be casually exposed to the internet.

For MySQL, MariaDB, PostgreSQL, Redis, and similar services, bind them to localhost or a private network where possible. Use strong unique credentials, restrict access with firewall rules, keep the software updated, enable useful logging, limit user permissions, and back up the data regularly.

If a database genuinely must be reachable remotely, use a VPN, private network, bastion host, or a tightly restricted firewall rule. An open public database port is not a reasonable default.

The same principle applies to internal dashboards, queues, cache servers, monitoring systems, and administrative tools. Internal services should be reachable by the systems and people that need them—not by the entire internet.

9. Use HTTPS and Manage Certificates

If your VPS serves a website or API, use HTTPS. TLS protects data in transit between visitors and the server and is now the ordinary baseline for public web services.

Use certificates from a trusted certificate authority, automate renewal where possible, and redirect HTTP traffic to HTTPS. Monitor certificate expiry dates so a simple renewal failure does not become an avoidable outage.

Also keep the web server and application framework updated, use a modern TLS configuration, protect certificate private keys, and apply appropriate security headers for the application you are running.

10. Set Up Logging and Monitoring

You cannot secure what you cannot see.

At minimum, monitor SSH login attempts, failed authentication, firewall activity, disk space, CPU and memory use, service failures, application errors, certificate expiry, backup success or failure, and unusual traffic patterns.

Useful tools and services can include journalctl, fail2ban, uptime monitoring, log aggregation, server-monitoring agents, and application-performance monitoring. The exact stack matters less than receiving useful information before a small problem becomes an outage or breach.

Set alerts for failures that require action: a disk nearly full, a failed backup, a service that has stopped, a certificate about to expire, repeated authentication failures, or a sharp and unexplained change in traffic.

11. Maintain Tested Backups

A backup that has never been restored is a hope, not a recovery plan.

Your backup plan should cover databases, application files, configuration files, and other data required to rebuild the service. Keep at least one backup copy outside the VPS, encrypt sensitive backup data where appropriate, and maintain retention rules that match the importance of the data.

A practical recovery routine is straightforward:

  1. Back up the database.
  2. Back up application files and configuration.
  3. Store a copy off-site.
  4. Encrypt sensitive backups.
  5. Restore into a staging environment.
  6. Document the recovery steps and keep them current.

Do not keep the only backup on the same VPS you are trying to protect. A hardware problem, account problem, destructive command, ransomware event, or compromised server can take production data and local backup data down together.

12. Separate Public and Administrative Access

Do not expose everything to the public internet.

A safer VPS design separates the public website or API from administrative interfaces, databases, internal tools, monitoring systems, and backup systems. Public visitors should be able to reach the public service—not the whole server environment.

Use a VPN, bastion host, private network, provider firewall, or tightly restricted host-firewall rules for administrative access. Restrict SSH to known IP addresses when that fits your working arrangement, and avoid exposing control panels or database tools broadly to the internet.

Segmentation limits the reach of an attacker if a public-facing service is compromised. It is one of the practical differences between a server that merely works and a server built to survive routine internet hostility.

VPS Security Checklist

Use this table before putting a VPS into production:

CheckPriorityWhat to verify
Operating system is updated🟩 EssentialApply current OS and package security updates before deployment
Non-root administrative user exists🟩 EssentialCreate a named admin user with sudo access; do not use root for daily work
SSH key authentication is configured🟩 EssentialConfirm key-based login works before disabling password login
Password SSH login is disabled🟩 EssentialDisable password authentication after key access is verified
Direct root SSH login is disabled🟩 EssentialSet PermitRootLogin no after confirming the admin user can connect
Firewall is enabled🟩 EssentialUse deny-by-default inbound rules and allow only required services
Only required ports are open🟩 EssentialExpose SSH, HTTP, and HTTPS only when needed; keep databases private
Unused services are removed🟧 HardeningReview listening services and remove anything not required
Databases are not publicly exposed🟩 EssentialBind databases to localhost or a private network where possible
Strong credentials are used🟩 EssentialUse unique passwords and keys; never reuse credentials across systems
MFA is enabled where available🟧 HardeningEnable MFA for provider, control-panel, and privileged accounts
Automatic security updates are configured🟧 HardeningEnable security updates where appropriate; test major upgrades in staging
HTTPS is configured🟩 EssentialUse TLS for public websites and APIs; redirect HTTP to HTTPS
Certificates renew automatically🟧 HardeningAutomate renewal and alert before certificates expire
Logs are collected🟪 OperationsCollect SSH, firewall, application, and system logs
Alerts are configured🟪 OperationsAlert on disk space, service failures, backup failures, and certificate expiry
Backups run automatically🟩 EssentialSchedule database, application, and configuration backups
Backups are stored off-site🟩 EssentialKeep at least one backup copy outside the VPS
Backups are encrypted where appropriate🟧 HardeningEncrypt sensitive backups at rest and in transit
Restore process has been tested🟩 EssentialRestore to staging and document recovery steps
Administrative access is separated from public access🟧 HardeningUse a VPN, bastion, private network, or restricted firewall rules for administration

Common VPS Security Mistakes

These are the mistakes that repeatedly turn manageable server risks into avoidable incidents:

MistakeWhy it creates riskBetter approach
Leaving password SSH login enabledIt leaves the server exposed to password guessing and credential-stuffing attempts.Use SSH keys and disable password authentication after testing access.
Using root for daily workA mistake or compromised session has unrestricted authority.Use a named administrative account and elevate with sudo only when necessary.
Exposing databases publiclyInternet-facing database ports are regularly scanned and attacked.Bind databases to localhost or a private network and restrict access tightly.
Ignoring updatesKnown vulnerabilities remain available for attackers to exploit.Apply security updates promptly and maintain a regular patching routine.
Running unnecessary servicesEvery unnecessary service expands the attack surface and maintenance burden.Remove or disable services that are not required for the server’s role.
Keeping the only backup on the VPSA server failure, compromise, or ransomware event can destroy production and backup data together.Keep encrypted backup copies off-site and test restoration regularly.
Reusing SSH keys or credentials everywhereOne compromised key or password can expose multiple systems.Use unique keys and credentials, then revoke access when it is no longer needed.
Storing secrets in plain textPasswords, tokens, and private keys can leak through files, repositories, backups, or logs.Use appropriate secret management, restricted file permissions, and encrypted storage.
Assuming the provider handles all securityThe provider usually protects the infrastructure, while you remain responsible for the operating system, applications, access, and data.Understand the shared-responsibility boundary and secure the part you control.
Discovering failures through usersProblems can persist longer when there is no monitoring or alerting.Monitor core services, capacity, certificates, backups, and authentication activity.

Frequently Asked Questions

Is a VPS secure by default?

No. A VPS is a server environment. Its security depends on the provider’s infrastructure, your operating-system configuration, access controls, software updates, firewall rules, monitoring, and backups.

Should I disable root login?

Usually, yes—after you have created and tested a non-root administrative user with SSH-key access. Direct root login over SSH is a common target for automated attacks.

Should I change the SSH port?

Changing the SSH port can reduce noisy automated scanning, but it is not meaningful protection on its own. SSH keys, restricted firewall access, patching, least privilege, and monitoring are more important than using an unusual port number.

Do I need a firewall if I use a cloud security group?

Often, yes. A host firewall is another layer of control and can continue protecting the server if network-level rules change. Use both where practical.

How often should I update a VPS?

Apply security updates promptly. For many servers, a weekly maintenance routine plus automatic security updates is a sensible baseline. Patch critical vulnerabilities and internet-facing services as soon as practical.

What is the first thing to do after getting a VPS?

Create a non-root user, configure SSH keys, verify access, update the system, enable a firewall, and arrange backups before deploying production work.

Security Is a Habit, Not a Setting

A secure VPS is not created by one command or one plugin.

It is created by a repeatable setup process: limited access, reduced exposure, current software, least privilege, useful monitoring, and backups you know how to restore. Review the server regularly, especially after adding software, changing access, or deploying a new application.

Make the server boring to attack: few open doors, strong authentication, updated software, and backups you know how to restore.