Skip to content
V.PSV.PS
Deploy a Server

How to Set Up a New VPS

A new VPS arrives in a reasonable but generic state. It has a public IP, SSH listening, a root account, and a set of defaults chosen to work everywhere rather than to suit you.

Within minutes of that IP going live, automated scanners will find it and start trying passwords. That’s not a sign of anything being wrong, it’s simply what the internet does to every reachable address, and it’s the reason the order of these steps matters.

Start with this setup checklist: update, add a user, set up keys, close the firewall, automate patching, and arrange the few things that make a future bad day shorter. Choose the examples for your distribution: Debian/Ubuntu or RHEL 9-family systems such as AlmaLinux 9 and Rocky Linux 9. Other releases and existing production systems may need adaptations. RHEL also needs access to the appropriate entitled repositories. Run server-side commands below as root unless the instructions say to use your local machine. Allow extra time for upgrades, testing, and backup restoration.

Before you start: Find the console

Do this first, because it’s the step that makes every other step safe to attempt.

Most providers’ control panels include a console, usually VNC or a serial console, that connects to the machine the way a monitor and keyboard would. It works when SSH doesn’t, which makes it the way out of a firewall rule that locked you out or an SSH configuration that went wrong. If yours doesn’t have one, find out from support how you’d get back in if SSH stopped working, before you need to know.

Open it once now, confirm you can log in, and make sure you have a password that works there. If the console uses local password login, test a non-root recovery account with sudo. Some providers instead offer a rescue environment or password-reset workflow; verify which recovery method yours uses.

Step 1: Update everything

The image was built at some point in the past, and security updates have been published since.

Debian or Ubuntu:

apt update && apt full-upgrade -y

RHEL 9, AlmaLinux 9, or Rocky Linux 9:

dnf upgrade --refresh -y

Reboot afterwards if the kernel was updated. Ubuntu flags this for you at login; on Debian, the simple rule is to reboot whenever a linux-image package was upgraded. On RHEL-family systems, reboot after a kernel update to boot the new kernel as well. Doing it now, before the server hosts a workload, avoids interrupting users. Doing it later, on a server running something, means scheduling.

Step 2: Create a user that isn’t root

Working as root all the time means every typo runs with full privileges, and it means the account everyone tries to brute force is the one you actually use.

Debian or Ubuntu:

adduser yourname
usermod -aG sudo yourname

RHEL 9-family:

dnf install sudo
useradd -m yourname
passwd yourname
usermod -aG wheel yourname

Replace yourname with the account you want to create. Verify that the sudo policy permits the wheel group before relying on the RHEL-family account.

Install sudo with apt install sudo first if this minimal image lacks it. Other distributions use different commands and may use the wheel group. Set a real password for this account even if you plan to log in with keys, because this is the password the console will ask for.

Step 3: Set up SSH keys

Keys replace a secret someone can guess with one they can’t. If you don’t have a keypair, generate one on your own machine rather than on the server.

ssh-keygen -t ed25519 -C "your comment"
ssh-copy-id yourname@your-server-ip

Ed25519 is a suitable default on systems whose crypto policy permits it. RHEL systems in FIPS mode do not support Ed25519; use an approved key type, such as RSA with ssh-keygen -t rsa -b 3072, following the system’s policy. Keep the private key on your machine and protect it with a passphrase.

Now test it. Open a second terminal, log in with the key, and confirm sudo -v succeeds before changing anything else. Keeping your original session open while you test in a new one is the habit that prevents most lockouts.

Step 4: Lock down SSH

Once key login is confirmed working, turn off the two things that scanners rely on. Rather than editing the main config file, create a drop-in at /etc/ssh/sshd_config.d/00-hardening.conf containing:

PermitRootLogin no
PasswordAuthentication no
KbdInteractiveAuthentication no

The drop-in matters because of a detail that trips people up on current distributions. On Debian and Ubuntu, sshd_config starts with an Include /etc/ssh/sshd_config.d/*.conf line, and sshd keeps the first value it reads for each setting, so anything in that directory beats what’s written further down the main file. Cloud images frequently ship a drop-in such as 50-cloud-init.conf that sets PasswordAuthentication yes, and editing the main file alone can leave password login quietly switched on. A file such as 00-hardening.conf is read early on these distributions, but inspect existing files and any Match blocks; verify the effective configuration for the user and address you actually use. Disabling keyboard-interactive authentication is appropriate for this key-only example, but can disable PAM-based MFA if you use it.

Validate the configuration, check what sshd will actually use, then reload the service:

sshd -t
sshd -T | grep -Ei 'passwordauthentication|kbdinteractiveauthentication|permitrootlogin'

Reload the service for your distribution:

# Debian or Ubuntu:
systemctl reload ssh
# RHEL-family:
systemctl reload sshd

On RHEL-family systems, inspect the existing SSH includes and drop-ins rather than assuming the Debian/Ubuntu file ordering. Use sshd -t and sshd -T to check your changes before reloading. Leave SELinux enforcing; custom SSH ports also require an appropriate SELinux port label as well as a firewall rule. With your original session still open, test a fresh login in another terminal before closing anything.

Changing the SSH port is often suggested at this point. It reduces log noise and does very little for security; key-only authentication is what actually closes the door. Do it if the quieter logs appeal to you, not as a substitute for the step above. If you do, allow the new port in Step 5 instead of the OpenSSH profile, which only covers port 22, and note that some Ubuntu images use socket activation. Check systemctl status ssh.socket and your release’s instructions before changing the port.

Step 5: Turn on the firewall

A listening service may be reachable wherever existing firewall rules permit it. Configure the firewall deliberately so only the services you intend to expose are accessible. On Debian or Ubuntu, install UFW if it is absent with apt install ufw; the image may already include a firewall configuration, so inspect it first.

On RHEL, AlmaLinux, or Rocky Linux, use the distribution’s usual firewalld tooling instead of the UFW commands below. Install it with dnf install firewalld if needed, then follow Red Hat’s firewalld guide. Check which zone applies to the public interface, allow your actual SSH port before enabling or changing filtering, and verify both runtime and persistent rules. Avoid managing the same firewall with UFW and firewalld at the same time.

ufw default deny incoming
ufw default allow outgoing
ufw allow OpenSSH
ufw enable
ufw status verbose

Check that the OpenSSH profile matches the port you actually use and that UFW IPv6 support is enabled if the server has IPv6. Container-published ports and a provider firewall may need separate rules. The order matters. Allow SSH first, then enable, or you’ll disconnect yourself the moment the rules load. This is the single most common way people lock themselves out of a new server, and it’s why the first thing you did was find the console.

Add ports as you add services, not in advance:

ufw allow 80/tcp
ufw allow 443/tcp

Ubuntu’s firewall documentation covers the rest, including rate limiting and per-source rules. If you prefer working with nftables directly, that’s fine too; the principle is the same, which is that the default should be deny.

RHEL-family firewall example

Use firewalld instead of the UFW commands above. If it is not installed, run dnf install firewalld. Before starting an inactive firewall, inspect its saved zones and allow your actual SSH port in the zone that will apply to the public interface. Use firewall-offline-cmd for offline configuration, then start it with systemctl enable --now firewalld. Keep console access ready and your current SSH session open.

With firewalld running, inspect the active zones:

firewall-cmd --get-active-zones
firewall-cmd --list-all-zones

The following example assumes the public interface uses the public zone and SSH uses port 22. Substitute the actual zone and port. Apply and save the SSH rule, then test a new SSH connection:

firewall-cmd --zone=public --add-service=ssh
firewall-cmd --permanent --zone=public --add-service=ssh
firewall-cmd --zone=public --list-all
firewall-cmd --permanent --zone=public --list-all

When you deploy a web server, allow its HTTP and HTTPS services in both configurations:

firewall-cmd --zone=public --add-service=http --add-service=https
firewall-cmd --permanent --zone=public --add-service=http --add-service=https

Review other allowed services and the zone’s target as well. Adding these rules does not remove services already permitted by the image. Do not run the UFW and firewalld examples together.

Step 6: Automate security updates

The patch you don’t apply is the one that matters, and the realistic way to stay current is to not rely on remembering.

Debian or Ubuntu:

apt install unattended-upgrades
dpkg-reconfigure -plow unattended-upgrades

Inspect /etc/apt/apt.conf.d/50unattended-upgrades and the apt timers rather than assuming every image has identical defaults. Enable the origins you intend, test with unattended-upgrade --dry-run --debug, and decide how service restarts and reboots will be handled. The Debian documentation explains the configuration.

RHEL 9-family: Install the automatic-update tool:

dnf install dnf-automatic

In /etc/dnf/automatic.conf, review the [commands] section and set upgrade_type = security, download_updates = yes, and apply_updates = yes if you want unattended security installation. Then enable the timer that uses those settings:

systemctl enable --now dnf-automatic.timer
systemctl list-timers 'dnf-automatic*'

Check logs and available repository security metadata to confirm the intended updates are being applied. Other dnf-automatic timers can override download/install settings; see Red Hat’s automatic-update guide. This example targets version 9; verify the tooling for other major releases.

Choose reboot windows around your users and test that services restart correctly. If reboots remain manual, monitor pending updates and schedule them promptly.

Step 7: Set the basics

Three small things that save confusion later.

Set the hostname so you know which machine you’re on:

hostnamectl set-hostname web01

Set the timezone to UTC. Server logs across multiple machines are far easier to correlate when they all agree on time, and UTC has no daylight saving transitions to produce an hour of duplicate or missing timestamps:

timedatectl set-timezone UTC

Set reverse DNS for your IP, through the provider’s control panel or support, if the server will send mail or appear in anyone else’s logs. While you’re there, note that many providers block outbound port 25 by default to limit spam, so a mail server needs that unblocked or needs to relay through a sending service.

Step 8: Add swap if memory is tight

On a server with 1 or 2 GB of memory, a small swap file is a reasonable safety net. It gives the kernel somewhere to put idle pages and can prevent the out-of-memory killer from ending your database during a brief spike.

Run swapon --show first and confirm /swapfile does not already exist; do not overwrite an existing swap file or duplicate its fstab entry. The example suits supported ext4 or XFS setups on either distribution family. On RHEL-family systems with SELinux enforcing, run restorecon -v /swapfile after creating the file and before activation; investigate any denial rather than disabling SELinux. On Btrfs, dd alone is not a safe fallback: use the Btrfs swap-file procedure, including NOCOW and layout restrictions, or btrfs filesystem mkswapfile where supported. Verify activation before making it persistent.

fallocate -l 2G /swapfile
chmod 600 /swapfile
mkswap /swapfile
# RHEL-family systems with SELinux enforcing:
# restorecon -v /swapfile
swapon /swapfile
swapon --show
# Only after activation succeeds and no matching entry exists:
echo '/swapfile none swap sw 0 0' >> /etc/fstab

Step 9: Arrange monitoring and backups

These are the two that get postponed indefinitely, and they’re the two that determine how bad a future incident is.

Monitoring means something outside the server checking that your service responds, and alerting you somewhere you’ll notice. An uptime check against a URL, with notifications to your phone, takes a few minutes to set up and is the difference between learning about an outage from a dashboard and learning about it from a customer.

Backups mean a copy somewhere else, and a restore you’ve actually performed. A snapshot may share the original server’s storage or account failure risks. Confirm its physical location and isolation, and retain an independently recoverable copy. Set up whatever mechanism suits your data, then restore it once to confirm the result is usable and to find out how long the process takes.

Included backup capacity varies across our product families: Performance KVM VPS includes two backup slots, while Edge KVM VPS includes one. Check the schedule and restore process for your plan; the number of slots alone does not tell you how often a backup is taken. Keep an independently recoverable copy of critical data as well.

Everything else on this list protects the server. These two protect you from the server.

Step 10: Write down how it works

Two paragraphs in a file you can reach from your phone: what this server does, where the configuration lives, how the service starts, where backups go, and anything non-obvious you did during setup.

It takes three minutes while everything is fresh and it’s worth a great deal in six months, when the details have evaporated and something has broken.

What to skip for now

A few things commonly recommended that can wait, or that matter less than they appear to.

  • Fail2ban is useful mostly for reducing log noise once password authentication is already disabled, since there’s nothing left to brute force. Install it if the logs bother you.

  • Hardening scripts that apply dozens of kernel and service tweaks tend to create confusing behavior later, when something doesn’t work and nobody remembers what was changed. Make changes you understand.

  • Installing a control panel on day one is worth a pause. A panel can be useful on a VPS, but it adds software to patch, exposed interfaces to protect, and resource requirements to plan for.

Wrapping up

Update, create a user, set up keys, disable password and root login, enable the firewall with SSH allowed first, automate security updates, set hostname and timezone, add swap if memory is tight, and arrange monitoring and backups you’ve tested.

The basic configuration may take minutes; updates, recovery tests, monitoring, and a verified restore take longer. This is a starting checklist rather than a complete security review. Everything after it is building whatever you got the server for.

Thanks for reading! If you’re setting up a new box, V.PS runs KVM VPS in 11 cities with full root access, OS rebuilds from the client area, free 24x7 support on every plan, and a public looking glass at every location so you can check the network before you order. Our documentation walks through ordering and rebuilding a server, and support can help with provider-side pieces like reverse DNS. If you’re still choosing a plan, our guide to how much RAM, CPU and storage you actually need is a good place to start.

Ready to get started? Deploy a server or contact our team if you need help choosing a plan.

Frequently asked questions about setting up a new VPS

What should I do first on a new VPS?

Find and test the console in your provider’s control panel, then update the system. The console is what rescues you from a firewall or SSH mistake later, and it’s far better to confirm it works before you need it.

Should I disable root login over SSH?

Yes, once you’ve created another account with sudo and confirmed key-based login works for it. Disabling root login and password authentication together removes what automated scanners are actually attempting.

Is changing the SSH port worth doing?

It reduces log noise from automated scanning and adds very little real security, since a port scan finds the new port quickly. Key-only authentication is the change that matters; the port is cosmetic.

How do I avoid locking myself out with the firewall?

Allow SSH before enabling the firewall, not after, and keep your existing session open while you test a new connection in a second terminal. If it does go wrong, the provider’s console gets you back in.

Do I need fail2ban?

It’s optional once password authentication is disabled, because there’s no password left to guess. Its main benefit at that point is quieter logs. Install it if you find the noise distracting rather than as a core security measure.

Should I set up swap on a VPS?

On a server with 1 or 2 GB of memory, a small swap file is sensible insurance against a brief spike triggering the out-of-memory killer. It isn’t a replacement for enough memory, and sustained swapping means the plan is undersized.

Share