New Ubuntu VPS? 10 Things You Should Do First
A practical first-day checklist for securing and preparing a fresh Ubuntu VPS before deploying applications.
1. Before You Start
Getting access to a new VPS is only the beginning. Before deploying Docker containers, databases, websites or production applications, you should establish a clean and reasonably secure server baseline.
A fresh Ubuntu VPS often gives you direct root access and may allow password-based SSH login. Those defaults are convenient during initial provisioning, but they should not normally become your everyday production setup.
Do not disable root/password SSH authentication until SSH-key login for your new administrator has been tested successfully in a separate terminal.
You will need:
- the public IP address of your VPS
- the initial login details supplied by the VPS provider
- a local Linux, macOS or compatible SSH environment
- permission to administer the server
Throughout this guide, replace YOUR_VPS_IP with the actual public IP address of your VPS. We will also use youradmin as the example administrator username. Choose your own username in production.
2. Log In to the VPS
New Ubuntu VPS instances commonly begin with root access enabled. From your local computer, connect with SSH:
ssh root@YOUR_VPS_IPIf your provider created a different initial account, use that account instead. Once connected, verify that you are operating on the intended server before making configuration changes.
hostname
whoamiThe important objective at this stage is simply to confirm that administrative access works.
3. Update Ubuntu
Before installing application software, update the package index and install available upgrades.
apt update && apt upgrade -yWhen the upgrade completes, reboot the VPS. Your SSH session will close during the reboot.
rebootWait for the VPS to become available again and reconnect:
ssh root@YOUR_VPS_IPKeeping the operating system updated before configuring the rest of the server reduces the chance of building your production environment on top of outdated packages.
4. Create a Normal Administrator
Using root for every server task is unnecessary. Create a normal administrator account:
adduser youradminUbuntu will ask you to create a password and may request some optional account information. Next, allow this user to perform administrative operations through sudo:
usermod -aG sudo youradminYour server now has root for emergency or system-level administration, and youradmin for normal server management.
Before restricting root access, make sure the new administrator account works. Do not skip that verification.
5. Configure SSH Key Authentication
SSH keys are preferable to relying on a reusable account password for remote administration. On your local computer, first check whether you already have SSH keys:
ls -la ~/.sshIf you already use a key such as id_ed25519, do not overwrite it. For a dedicated VPS administration key, create a named Ed25519 key:
ssh-keygen -t ed25519 -C "vps-admin-key" -f ~/.ssh/vps_adminThis creates ~/.ssh/vps_admin as the private key and ~/.ssh/vps_admin.pub as the public key.
Never copy your private SSH key to the VPS. Only the .pub public key belongs in authorized_keys.
Display the public key and copy the complete output:
cat ~/.ssh/vps_admin.pubOn the VPS, create the administrator's SSH directory and open the authorized keys file:
sudo mkdir -p /home/youradmin/.ssh
sudo nano /home/youradmin/.ssh/authorized_keysPaste the public key generated on your local computer, save the file, then configure ownership and permissions:
sudo chown -R youradmin:youradmin /home/youradmin/.ssh
sudo chmod 700 /home/youradmin/.ssh
sudo chmod 600 /home/youradmin/.ssh/authorized_keysIncorrect .ssh permissions are a common reason SSH public-key authentication fails.
6. Test Your New SSH Login
Do not close your existing administrator/root session yet. Test the new login in a second terminal first.
Open a second terminal on your local computer and test:
ssh -i ~/.ssh/vps_admin youradmin@YOUR_VPS_IPIf authentication succeeds, verify the user and sudo access:
whoami
sudo whoamiYou should see youradmin from the first command and root from the sudo command. Only continue with SSH hardening after this test succeeds.
Optional: Simplify Your Local SSH Command
Instead of typing the IP address, username and key path every time, create a local SSH configuration.
nano ~/.ssh/configHost myvps
HostName YOUR_VPS_IP
User youradmin
IdentityFile ~/.ssh/vps_adminchmod 600 ~/.ssh/config
ssh myvps7. Harden SSH
Once key authentication for the administrator account has been tested successfully, you can restrict less desirable SSH login methods.
sudo nano /etc/ssh/sshd_configMake sure the relevant settings are:
PermitRootLogin no
PasswordAuthentication no
PubkeyAuthentication yesThen restart SSH:
sudo systemctl restart sshOpen another terminal and test the key login again before closing your existing session:
ssh -i ~/.ssh/vps_admin youradmin@YOUR_VPS_IPThis simple habit can prevent accidentally locking yourself out of the VPS.
8. Configure the Firewall
For a typical public web server, you normally need SSH, HTTP and HTTPS. Ubuntu provides UFW as a straightforward firewall interface.
sudo ufw allow OpenSSH
sudo ufw allow 80
sudo ufw allow 443
sudo ufw enable
sudo ufw statusA basic web-server configuration should allow the required management and web traffic without exposing unnecessary application or database ports.
What About PostgreSQL Port 5432?
Do not expose PostgreSQL port 5432 publicly unless your architecture explicitly requires remote database access and it is properly secured.
If your application and PostgreSQL run through Docker Compose on the same VPS, the database can normally stay inside the Docker network.
9. Install Essential Server Tools
Before moving into deployment, install a small set of useful administration tools.
sudo apt update
sudo apt install -y curl wget git unzip htop nano ca-certificates gnupg lsb-releaseThese tools are commonly useful for downloading installation files, cloning repositories, inspecting system resources, editing server configuration, installing trusted package repositories and troubleshooting deployment problems.
You do not need to install every possible utility immediately. Keep the base server reasonably small and add software when the deployment actually requires it.
10. Run Basic Verification
Before installing Docker or deploying an application, verify the state of the VPS.
Check disk space
df -hCheck memory
free -mCheck the current user
whoamiCheck UFW
sudo ufw statusCheck SSH
ssh -i ~/.ssh/vps_admin youradmin@YOUR_VPS_IPAt this point you should have:
- an updated Ubuntu server
- a non-root administrator
- SSH key authentication
- direct root SSH access disabled
- password-based SSH authentication disabled
- a firewall allowing SSH, HTTP and HTTPS
- useful administration tools installed
That gives you a much cleaner starting point for application deployment.
Quick Checklist
11. What Should You Do Next?
A secure base operating-system configuration is only the first part of preparing a production VPS. The next step depends on what you plan to host.
For a modern Docker-based application, a typical progression is:
This article intentionally stops before those deployment-specific steps. Keeping each subject separate makes it easier to follow the guide you actually need instead of working through one enormous server-setup document.
Continue the Ubuntu VPS Series
Also Coming
Deploy a Private GitHub Repository to an Ubuntu VPS
Coming SoonAlso Coming