Skip to main content
VPS NEPALby NepalCloud Host
PricingAbout
Client area Explore VPS plans
View VPS plansCompare pricing
VPS hosting
All VPS plansSmall VPS · from NPR 2,999/yearUbuntu VPSWindows VPSOperating systems
Solutions
Application hostingn8n automationDatabase VPSDevelopment VPSWeb hostingDomainsDedicated servers
Resources
DocumentationConnect over SSHGuides & articlesFAQsSupportContact
About VPS NepalContact supportOpen client area
Tutorials

Complete Ubuntu Server Setup Guide for VPS

Step-by-step guide to setting up and configuring Ubuntu Server on your VPS, including essential packages, security configuration, and optimization.

VN

VPS Nepal

Publisher

Jan 08, 2024
18 min read
Ubuntu ServerServer SetupLinuxNginxApacheMySQLPostgreSQL
Complete Ubuntu Server Setup Guide for VPS - VPS hosting tutorial and guide featured image

Complete Ubuntu Server Setup Guide for VPS

Setting up an Ubuntu server properly is crucial for security, performance, and maintainability. This comprehensive guide covers everything from initial configuration to production-ready setup.

Initial Server Setup

Update System

# Update package lists
sudo apt update

# Upgrade all packages
sudo apt upgrade -y

# Install essential packages
sudo apt install -y curl wget git vim htop net-tools ufw

Create Non-Root User

# Add new user
sudo adduser yourusername

# Add user to sudo group
sudo usermod -aG sudo yourusername

# Switch to new user
su - yourusername

SSH Configuration

SSH Key Setup

# Generate SSH key pair on local machine
ssh-keygen -t ed25519 -C "your_email@example.com"

# Copy public key to server
ssh-copy-id yourusername@your-server-ip

# Disable password authentication
sudo sed -i 's/#PasswordAuthentication yes/PasswordAuthentication no/' /etc/ssh/sshd_config

# Change SSH port (optional)
sudo sed -i 's/#Port 22/Port 2222/' /etc/ssh/sshd_config

# Restart SSH service
sudo systemctl restart sshd

Firewall Configuration

UFW Setup

# Enable UFW
sudo ufw enable

# Allow SSH (use custom port if changed)
sudo ufw allow 2222/tcp

# Allow HTTP and HTTPS
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp

# Check status
sudo ufw status

Web Server Installation

Nginx Installation

# Install Nginx
sudo apt install -y nginx

# Start and enable Nginx
sudo systemctl start nginx
sudo systemctl enable nginx

# Basic configuration
sudo vim /etc/nginx/sites-available/default

Apache Installation (Alternative)

# Install Apache
sudo apt install -y apache2

# Start and enable Apache
sudo systemctl start apache2
sudo systemctl enable apache2

Database Setup

MySQL/MariaDB Installation

# Install MariaDB
sudo apt install -y mariadb-server

# Secure installation
sudo mysql_secure_installation

# Create database and user
sudo mysql -u root -p

PostgreSQL Installation

# Install PostgreSQL
sudo apt install -y postgresql postgresql-contrib

# Switch to postgres user
sudo -u postgres psql

# Create database and user
CREATE DATABASE yourdb;
CREATE USER youruser WITH PASSWORD 'yourpassword';
GRANT ALL PRIVILEGES ON DATABASE yourdb TO youruser;

SSL/TLS Certificates

Let's Encrypt with Certbot

# Install Certbot
sudo apt install -y certbot python3-certbot-nginx

# Obtain certificate
sudo certbot --nginx -d yourdomain.com

# Test renewal
sudo certbot renew --dry-run

Monitoring and Logging

System Monitoring

# Install monitoring tools
sudo apt install -y htop iotop ncdu

# Install monitoring stack
sudo apt install -y prometheus-node-exporter

# Check system resources
htop
df -h
free -h

Log Management

# Install log rotation
sudo apt install -y logrotate

# Configure logrotate for custom logs
sudo vim /etc/logrotate.d/yourapp

Security Hardening

Automatic Updates

# Install unattended-upgrades
sudo apt install -y unattended-upgrades

# Configure automatic updates
sudo dpkg-reconfigure --priority=low unattended-upgrades

Fail2Ban Installation

# Install Fail2Ban
sudo apt install -y fail2ban

# Configure jails
sudo vim /etc/fail2ban/jail.local

# Restart service
sudo systemctl restart fail2ban

Backup Strategy

Automated Backups

# Create backup directory
sudo mkdir -p /backup

# Create backup script
sudo vim /usr/local/bin/backup.sh

Cron Jobs for Automation

# Edit crontab
sudo crontab -e

# Add backup job (daily at 2 AM)
0 2 * * * /usr/local/bin/backup.sh

Performance Optimization

System Tuning

# Optimize sysctl settings
sudo vim /etc/sysctl.conf

# Apply changes
sudo sysctl -p

Nginx Optimization

# Optimize Nginx configuration
sudo vim /etc/nginx/nginx.conf

# Test configuration
sudo nginx -t

# Reload Nginx
sudo systemctl reload nginx

Final Steps

System Information

# Check system status
sudo systemctl status nginx
sudo systemctl status mysql
sudo ufw status

# System information
uname -a
lsb_release -a

Documentation

Keep detailed documentation of your setup, including:

  • Server specifications
  • Installed software versions
  • Configuration changes
  • Backup procedures
  • Emergency contacts

Your Ubuntu server is now properly configured and ready for production use. Regular maintenance, monitoring, and security updates are essential for keeping your server secure and performant.

Share this article:
VN

VPS Nepal

Publisher

Technical articles published by VPS Nepal.

Table of Contents

Article Stats

Reading Time18 min
Likes0
Comments0
PublishedJan 08, 2024

Tags

Ubuntu ServerServer SetupLinuxNginxApacheMySQLPostgreSQL

Related Articles

10 Best Practices for Securing Your VPS Server - Related VPS hosting article
Security
15 min read•Jan 10

10 Best Practices for Securing Your VPS Server

Essential security measures every VPS administrator should implement to protect their server from threats and unauthorized access.

Comments (0)

No comments yet.

Be the first to share your thoughts!

VPS NEPAL

Clear VPS pricing, capable infrastructure and practical support for people building on the web in Nepal.

A service by NepalCloud Host PVT. LTD.

support@nepalcloud.host Kathmandu, Nepal

Hosting

  • VPS hosting plans
  • Small VPS
  • Windows VPS
  • Ubuntu VPS
  • Web hosting
  • Domain registration

Resources

  • Documentation
  • Guides & articles
  • Support centre
  • Frequently asked questions
  • Contact

Legal

  • Privacy Policy
  • Terms of Service
  • Acceptable Use Policy
  • Fair Use Policy
  • Refund Policy

© 2026 NepalCloud Host PVT. LTD. All rights reserved.

Client portal