Thursday, February 20, 2025

How to Install Ubuntu Server 2025 Step by Step



Setting up your first Linux server can initially seem daunting, particularly for those new to server administration. However, the process is surprisingly straightforward, and with the correct guidance, you can have your Ubuntu server operational in a short amount of time.

This step-by-step guide will walk you through the entire setup, ensuring your server is not only functional but also secure and optimized for future use. Whether you aim to set up a web server, host applications, or simply explore Linux administration, this guide will provide a quick and confident start.

By the end of this tutorial, you will have a fully operational Ubuntu server, remotely accessible and customizable to meet your specific requirements.

Step 1: Choosing a Cloud Provider or Local Installation (5 Minutes)

Before you begin setting up your Ubuntu server, you need to decide on its location. You have two primary options: renting a cloud-based server (VPS) or installing Ubuntu Server on a physical machine. Your choice will depend on your intended use, budget, and level of technical expertise.

Option 1: Cloud Server (VPS) - Recommended for Beginners

For those without spare hardware or who prefer to avoid hardware configuration, a cloud-based Virtual Private Server (VPS) is the simplest route. Cloud providers offer pre-configured Ubuntu servers that can be deployed in minutes.

Popular beginner-friendly cloud providers include:

Steps to Deploy an Ubuntu VPS:

  1. Sign up: Create an account with your chosen cloud provider.
  2. Create a server instance: Initiate a new server instance, often termed a "droplet" (DigitalOcean) or "instance" (AWS).
  3. Choose Ubuntu Version: Select Ubuntu 24.04 LTS, the latest Long-Term Support version, ensuring several years of security updates.
  4. Select a plan: Choose a plan that aligns with your needs. For experimentation, a small instance with 1 CPU and 1GB RAM is sufficient.
  5. Set up authentication: Opt for password or SSH key authentication. SSH keys are more secure and highly recommended.
  6. Launch and note IP: Launch the server and record the provided IP address, which is essential for connecting to your server.

Your cloud-based Ubuntu server is now set up and ready for access.

Option 2: Local Ubuntu Server Installation

If you have a spare computer or prefer to run Ubuntu on your hardware, you can manually install Ubuntu Server. This option is suitable for setting up a home lab, a private web server, or for in-depth Linux administration practice.

Requirements:

  • A computer for Ubuntu Server installation.
  • A USB flash drive (minimum 4GB).
  • A separate computer to create a bootable USB drive.

Steps for Local Installation:

  1. Download Ubuntu Server ISO: Visit the official Ubuntu website and download the latest Ubuntu Server 24.04 LTS ISO file.
  2. Create a bootable USB drive:
    • Windows: Use Rufus (https://rufus.ie/en/)

      1. Insert your USB drive.
      2. Open Rufus and select the downloaded ISO.
      3. Click 'Start' and wait for completion.
    • Linux/macOS: Use the dd command:

      Bash
      sudo dd if=ubuntu-24.04.1-live-server-amd64.iso of=/dev/sdX bs=4M status=progress
      

      Replace /dev/sdX with your USB device path (use lsblk to find this).

  3. Boot from USB: Insert the USB into your target machine, restart, and enter BIOS/UEFI settings (usually via F2, F12, DEL, or ESC during boot). Set the USB drive as the primary boot device and save changes.
  4. Ubuntu Server Installer: The installer will load automatically.
  5. Follow Installation Steps:
    • Choose language and keyboard layout.
    • Select 'Install Ubuntu Server'.
    • Set up username and password.
    • Choose disk partitioning (Guided – Use Entire Disk is simplest).
    • Select 'Install OpenSSH Server' (recommended for remote access).
    • Complete installation and reboot.

Once installed, log in with your created credentials.

Choosing the Right Option

FactorCloud Server (VPS)Local Installation
Best forBeginners, web hosting, remote Linux learningHome labs, private servers, advanced users
Setup Time5-10 minutes20-30 minutes
HardwareNone requiredSpare PC or server needed
AccessRemote via SSHDirect login or SSH (if configured)
CostMonthly fee (from ~$5/month for basic VPS)Free (excluding electricity and maintenance)
PerformancePlan-dependentHardware-dependent

For Linux novices or those seeking a straightforward setup, a cloud VPS is ideal. Conversely, if you have spare hardware and desire complete hardware control, local installation provides a valuable learning experience.

After setting up your Ubuntu server, the next step is to access and update it with the latest security patches.

Bash
sudo apt update && sudo apt upgrade -y

Step 2: Accessing Your Ubuntu Server (2 Minutes)

With your Ubuntu server running, you now need to access it. This is where you begin interacting with your server, installing software, and configuring it to your needs.

Accessing a Cloud Server (VPS)

Cloud providers like DigitalOcean, Linode, AWS, and Google Cloud will provide:

  • A public IP address (e.g., 192.168.1.100).
  • A default username (typically root or ubuntu).
  • Password or SSH key for authentication.

Connecting via SSH:

  • Linux/macOS: Open your terminal and use the command:

    Bash
    ssh ubuntu@your-server-ip
    

    Replace your-server-ip with your server's actual IP address.

  • Windows: Use PuTTY (https://www.putty.org/):

    1. Open PuTTY and enter your server's IP in 'Host Name (or IP address)'.
    2. Select 'SSH' as the connection type and click 'Open'.
    3. Enter your password when prompted (if using password authentication). For SSH keys, load your private key in PuTTYgen before connecting.

Successful login will display a welcome message with system details.

Accessing a Local Ubuntu Server

For local installations, power on the machine, wait for the login prompt, and enter the username and password created during setup. You will then access the Ubuntu command-line interface (CLI).

After logging in, update your server to ensure it has the latest security patches:

Bash
sudo apt update && sudo apt upgrade -y

Step 3: Creating a New User and Securing SSH Access (5 minutes)

By default, cloud providers often provide root user access. While root has full system control, it's risky for daily tasks. Accidental commands or security breaches can severely impact the system.

For enhanced security, create a new user with administrative rights and properly configure SSH access.

1. Create a New User

Add a new user for server tasks, replacing yourusername with your desired username:

Bash
sudo adduser yourusername

Set a strong password when prompted and fill in optional fields or press Enter to skip.

2. Grant Administrative Privileges (sudo access)

Grant your new user administrative (sudo) privileges:

Bash
sudo usermod -aG sudo yourusername

Verify sudo access by switching to the new user and running:

Bash
su - yourusername
sudo whoami

If the output is root, sudo access is correctly configured.

3. Set Up SSH Key Authentication

SSH keys are more secure than passwords. Generate an SSH key pair on your local computer:

Bash
ssh-keygen -t rsa -b 4096

Press Enter to save to the default location (~/.ssh/id_rsa). Set a passphrase for added security (optional).

Copy SSH Key to Server:

  • Cloud Server (using ssh-copy-id):

    Bash
    ssh-copy-id yourusername@your-server-ip
    
  • Manual Copy (if ssh-copy-id is unavailable):

    Bash
    ssh root@your-server-ip
    sudo mkdir -p /home/yourusername/.ssh
    sudo chmod 700 /home/yourusername/.ssh
    echo "your-public-key" | sudo tee -a /home/yourusername/.ssh/authorized_keys > /dev/null
    sudo chmod 600 /home/yourusername/.ssh/authorized_keys
    sudo chown -R yourusername:yourusername /home/yourusername/.ssh
    

    Replace "your-public-key" with the content of your id_rsa.pub file.

Test SSH key authentication by logging in with the new user:

Bash
ssh yourusername@your-server-ip

4. Disable Root Login and Password Authentication

Improve security by disabling root logins and password authentication in the SSH configuration:

Bash
sudo nano /etc/ssh/sshd_config

Modify these lines:

PermitRootLogin no
PasswordAuthentication no

Restart the SSH service:

Bash
sudo systemctl restart ssh

Test login via SSH with your new user. SSH access is now secured.

Step 4: Installing Essential Software (5 Minutes)

With your server secured, install essential software for efficient management and security.

Install Common Packages:

Bash
sudo apt install -y vim curl wget git htop unzip net-tools
  • vim: Powerful text editor for configuration files.
  • curl & wget: Command-line tools for downloading web files.
  • git: Version control for code repository management.
  • htop: Enhanced system resource monitoring tool.
  • unzip: For extracting .zip files.
  • net-tools: Network utilities like ifconfig.

Set Up UFW Firewall:

UFW (Uncomplicated Firewall) is essential for server security. Allow SSH traffic before enabling:

Bash
sudo ufw allow OpenSSH
sudo ufw enable
sudo ufw status

Configure Time and Synchronization:

Accurate server time is crucial. Ubuntu uses systemd-timesyncd for automatic time synchronization.

Bash
timedatectl
timedatectl list-timezones
sudo timedatectl set-timezone Asia/Kolkata
timedatectl

Replace Asia/Kolkata with your timezone.

Install Fail2Ban (Optional, Extra Security):

Fail2Ban protects against brute-force attacks:

Bash
sudo apt install -y fail2ban
sudo systemctl enable fail2ban
sudo systemctl start fail2ban
sudo systemctl status fail2ban

Enable Automatic Security Updates:

Enable automatic security updates:

Bash
sudo apt install -y unattended-upgrades
sudo dpkg-reconfigure --priority=low unattended-upgrades
cat /etc/apt/apt.conf.d/20auto-upgrades

Verify that APT::Periodic::Update-Package-Lists "1"; and APT::Periodic::Unattended-Upgrade "1"; are present.

Clean Up Unnecessary Files:

Remove temporary files and unused dependencies:

Bash
sudo apt autoremove -y
sudo apt autoclean

Step 5: Configuring a Web Server (Optional, 5–10 minutes)

For hosting websites or web applications, a web server is needed. Nginx and Apache are popular choices. This guide uses Nginx for its efficiency and beginner-friendliness.

Install Nginx on Ubuntu:

Bash
sudo apt update
sudo apt install -y nginx
nginx -v

Start and enable the Nginx service:

Bash
sudo systemctl start nginx
sudo systemctl enable nginx
sudo systemctl status nginx

Allow HTTP (port 80) and HTTPS (port 443) traffic through UFW:

Bash
sudo ufw allow 'Nginx Full'
sudo ufw status

Test Nginx by opening a web browser and navigating to http://your-server-ip. You should see the default Nginx welcome page.

Set Up a Basic Website (Optional):

Replace the default Nginx page with a custom website by editing /var/www/html/index.html:

Bash
sudo nano /var/www/html/index.html

Replace the content with:

HTML
<!DOCTYPE html>
<html>
<head>
    <title>Welcome to My Server</title>
    <style>
        body { text-align: center; font-family: Arial, sans-serif; margin-top: 50px; }
        h1 { color: #4CAF50; }
    </style>
</head>
<body>
    <h1>Success! Your Nginx Web Server is Running.</h1>
    <p>This is a test page hosted on Ubuntu.</p>
</body>
</html>

Refresh http://your-server-ip in your browser to view your custom page.

Enable HTTPS with Let's Encrypt (Optional):

Enable HTTPS using a free SSL certificate from Let's Encrypt:

Bash
sudo apt install -y certbot python3-certbot-nginx
sudo certbot --nginx

You have now successfully installed and configured an Nginx web server on your Ubuntu server.

Conclusion

You have successfully set up your first Ubuntu server in under 30 minutes. This guide provides a foundation, and there is much more to explore, such as hosting websites, databases, and applications. As you gain experience, you will appreciate the power and versatility of Linux servers. Happy hosting!

0 comments:

Post a Comment