VPS Setup from Scratch

A Virtual Private Server (VPS) gives you full control over your hosting environment. This guide walks you through setting up a production-ready server step by step.

Step 1: Initial Server Setup

SSH into your server and update packages:

ssh root@your-server-ip
apt update && apt upgrade -y

# Create a new user
adduser deploy
usermod -aG sudo deploy

# Switch to new user
su - deploy

Step 2: SSH Security

Disable root login and password authentication:

# Copy SSH key to new user
ssh-copy-id deploy@your-server-ip

# Edit SSH config
sudo nano /etc/ssh/sshd_config

# Set these values:
PermitRootLogin no
PasswordAuthentication no

sudo systemctl restart ssh

Step 3: Firewall Setup

sudo ufw allow OpenSSH
sudo ufw allow 'Nginx Full'
sudo ufw enable
sudo ufw status

Step 4: Install Docker

curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
sudo usermod -aG docker deploy
newgrp docker

Step 5: SSL with Let's Encrypt

sudo apt install certbot python3-certbot-nginx
sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com

Conclusion

Your VPS is now secured and ready for production deployments. Regular updates and monitoring will keep it running smoothly.