Complete Ubuntu VPS Setup Guide: SSH, Nginx, Python, Docker, SSL & More

date
Jan 24, 2025
slug
ubuntu-vps-setup-guide
status
Published
tags
Ubuntu
VPS
Server Setup
Nginx
Python
Docker
Docker Compose
SSL
Let's Encrypt
MongoDB
MongoDB Atlas
Security
SSH
Firewall
UFW
SSH Hardening
Python Development
Deadsnakes PPA
pub.dev
Package Management
Virtual Environment
System Optimization
Performance Tuning
Swap
Kernel Tuning
MOTD
Monitoring
Guide
Tutorial
How To
Linux
Server Administration
DevOps
summary
Set up a secure and optimized Ubuntu VPS with this comprehensive guide. Learn step-by-step how to configure SSH, install Nginx with a UI, set up a Python development environment (with multiple versions and uv), use Docker and Docker Compose, secure your server with Let's Encrypt SSL, integrate with MongoDB Atlas, optimize system performance, and implement essential monitoring and maintenance tasks. Perfect for developers and sysadmins!
type
Post

Features:

  • 🔒 Secure SSH configuration
  • 🐍 Python environment with deadsnakes PPA
  • 🚀 Nginx with UI management
  • 🐳 Docker and Docker Compose
  • 🔑 SSL/TLS with Let's Encrypt
  • 📊 MongoDB Atlas integration
  • 💾 Swap and system optimization
  • 🔄 Auto-renewal and maintenance scripts
  • ⏰ Custom MOTD with system stats
  • 📝 Memory monitoring and management
Perfect for developers setting up a new VPS or standardizing their server configuration. Includes detailed step-by-step instructions and best practices for security and performance.

Usage:

  1. Follow sections in order
  1. Copy-paste commands as needed
  1. Modify configurations according to your needs

Requirements:

  • Ubuntu Server (Latest LTS recommended)
  • Root or sudo access
  • Basic command line knowledge

Post-Setup:

  • Nginx UI accessible at port 9000
  • Python versions: 3.8 through 3.12
  • UV package manager for faster Python package installation
  • Optimized for both web hosting and development

Table of Contents

  1. Initial System Setup
  1. Security Configurations
  1. System Optimizations
  1. Development Environment Setup
  1. Web Server Setup
  1. Database Setup
  1. Docker Setup
  1. SSL Configuration
  1. Monitoring and Maintenance

1. Initial System Setup

Context: This section focuses on the preliminary steps required to set up your VPS. It will cover creating a new user, setting up SSH for secure access, and updating the system to ensure all packages are up to date.

Create New User

Explanation: Creating a new user with sudo privileges enhances security by avoiding direct usage of the root user.

SSH Setup

Explanation: Setting up SSH keys allows for passwordless login, which is more secure than using passwords.

Configure SSH

Explanation: This configures the SSH daemon for enhanced security and prevents certain vulnerabilities.

System Updates

Explanation: Ensures all installed packages are up-to-date and includes some useful utilities.

MOTD (Message of the Day)

Explanation: This customizes the message displayed upon SSH login with some helpful system information.

2. Security Configurations

Context: This section is dedicated to security enhancements for your VPS. It will cover firewall setup, SSH hardening, and general security recommendations.

Firewall Setup

Explanation: Setting up a firewall is crucial for protecting the server from unauthorized access. ufw is used here for ease of use.

SSH Hardening

Explanation: SSH is a common target for attacks, so these steps will help further secure it.

3. System Optimizations

Context: This section focuses on improving the performance and efficiency of your VPS. It will include swap space configuration and kernel parameter tuning.

Swap Setup

Explanation: Swap space is used when the system runs out of RAM. It's created here and activated.

System Tuning

Explanation: Kernel tuning optimizes network and memory usage, and improves performance.

4. Development Environment Setup

Context: This section sets up the Python development environment on your VPS, including the installation of multiple Python versions, development packages, and the uv package installer.

Install Python Versions (Deadsnakes PPA)

Explanation: The Deadsnakes PPA provides multiple versions of Python for development.

Install uv (Fast Python Package Installer)

Explanation: uv is a fast alternative to pip for managing Python packages.

5. Web Server Setup

Context: This section covers the installation and basic configuration of Nginx as a web server, as well as the installation and setup of Nginx UI for easier management of your web server.

Install Nginx

Nginx Configuration

Note: The default Nginx config should work. If you have custom requirements, update this file appropriately.

Install Nginx UI

Configure Nginx UI


6. Database Setup

Context: This section covers the setup of MongoDB Atlas, including the installation of the MongoDB shell and database tools. It presumes an external database is being used rather than one installed directly on the server.

Install MongoDB Shell and Tools

Explanation: This section explains how to install the MongoDB shell and other relevant tools

7. Docker Setup

Context: This section details the installation of Docker and Docker Compose, which can be used for containerization of services.

Install Docker

Install Docker Compose


8. SSL Configuration

Context: This section covers how to install and configure SSL certificates for your domains using Let's Encrypt and Certbot.

Install Certbot

Obtain SSL Certificate

Auto-renewal Setup


9. Monitoring and Maintenance

Context: This section details how to set up system monitoring and includes regular maintenance tasks for your VPS, including memory monitoring and system updates.

Memory Monitoring Script

Add to Crontab

Explanation: This sets up a cron job to run the memory monitoring script regularly.
Add:

Final Steps

Explanation: These final steps include important considerations for completing the server setup, such as setting the timezone and creating backups.

Set Timezone

Create Backup Directory

Setup Completed

  • Access Nginx UI: https://your-server-ip:9000
  • Default credentials: admin/admin
  • Change default passwords
  • Configure firewall rules
  • Set up regular backups

Regular Maintenance Tasks

  1. System Updates:
    1. Docker Cleanup:
      1. Log Rotation:
        1. Certificate Renewal:

          Note:
          • You should have basic familiarity with Linux commands and command-line interfaces.
          • You should have a domain name configured to point to the server.
          • You should have a local machine with SSH capabilities.
          • You should have a basic understanding of networking and web servers.
          • My target is an Ubuntu server!
          • I included Explanations and Context for each section for better understanding
          What to do if you stuck? Go, get some help!

          © Satyendra Bongi 2025