How to Set Up a Linux Home Server from Start to Finish!

4 min read 2 months ago
Published on Aug 20, 2024 This response is partially generated with the help of AI. It may contain inaccuracies.

Table of Contents

Introduction

In this tutorial, you will learn how to set up a Linux home server from scratch using Debian. We'll cover everything from downloading the Debian ISO to configuring various services like Docker, NGINX, and a Minecraft server. This guide is perfect for anyone looking to create a versatile home server for hosting games, managing files, or running web applications.

Step 1: Download the Debian ISO

  • Visit the Debian website.
  • Choose the appropriate version for your hardware architecture (usually amd64 for most modern computers).
  • Download the ISO file to your local machine.

Step 2: Create Install Media from Linux

  • Insert a USB drive (4GB or more).
  • Open a terminal and find the drive name using lsblk.
  • Use dd to create a bootable USB:
    sudo dd if=/path/to/debian.iso of=/dev/sdX bs=4M status=progress
    
    • Replace /path/to/debian.iso with the actual path to your downloaded ISO.
    • Replace /dev/sdX with the correct drive identifier (be careful to select the right drive).

Step 3: Create Install Media from Windows

  • Download a tool like Rufus.
  • Insert your USB drive and open Rufus.
  • Select the Debian ISO and choose your USB drive.
  • Click "Start" to create the bootable media.

Step 4: Install Debian

  • Boot your computer from the USB drive.
  • Follow the on-screen prompts to install Debian.
  • Choose the appropriate options for your system (language, time zone, partitioning).
  • Make sure to install the OpenSSH server during setup for remote access.

Step 5: SSH in and Set Up Sudo

  • Once installed, log into your server.
  • Use SSH to connect from another machine:
    ssh username@your-server-ip
    
  • Install sudo if not included:
    apt update
    apt install sudo
    
  • Add your user to the sudo group:
    sudo usermod -aG sudo username
    

Step 6: Basic SSH Security Hardening

  • Change the default SSH port:
    • Open the SSH configuration file:
      sudo nano /etc/ssh/sshd_config
      
    • Change the line Port 22 to a different port.
  • Disable root login:
    • Set PermitRootLogin no.
  • Restart SSH:
    sudo systemctl restart ssh
    

Step 7: Disk Mirroring and Filesystems

  • Install mdadm for RAID support:
    sudo apt install mdadm
    
  • Create a RAID array:
    sudo mdadm --create --verbose /dev/md0 --level=mirror --raid-devices=2 /dev/sdX /dev/sdY
    
  • Format the new RAID array:
    sudo mkfs.ext4 /dev/md0
    

Step 8: Installing Docker

  • Update your package index:
    sudo apt update
    
  • Install Docker:
    sudo apt install docker.io
    
  • Enable and start Docker:
    sudo systemctl enable docker
    sudo systemctl start docker
    

Step 9: Configuring Web Server with NGINX

  • Install NGINX:
    sudo apt install nginx
    
  • Start NGINX:
    sudo systemctl start nginx
    
  • Configure your server blocks in /etc/nginx/sites-available/ and link them to sites-enabled.

Step 10: Configuring Minecraft Server

  • Run the following command to set up your Minecraft server:
    docker run -it -p 25565:25565 --name littleroot-minecraft -v /hdds/swraid/games/mcserver:/hmnt/mcserver -d debian bash
    

Step 11: Configuring File Server with Samba

  • Install Samba:
    sudo apt install samba
    
  • Configure Samba shares in the /etc/samba/smb.conf file.
  • Restart Samba:
    sudo systemctl restart smbd
    

Step 12: Setting Up a Firewall with UFW

  • Install UFW:
    sudo apt install ufw
    
  • Enable UFW and allow specific ports:
    sudo ufw allow ssh
    sudo ufw allow 25565
    sudo ufw enable
    

Step 13: Setting a Cool Message of the Day

  • Edit the MOTD file:
    sudo nano /etc/motd
    
  • Add your custom message.

Step 14: Setting a Cool Bash Prompt

  • Use the Bash Prompt Generator to create a custom prompt.
  • Update your .bashrc with the new prompt settings.

Conclusion

You've now set up a fully functional Linux home server! You've learned to install Debian, set up services like Docker, NGINX, and a Minecraft server, and secured your server with basic firewall settings. For further exploration, consider adding more applications or experimenting with additional configurations to enhance your server's capabilities. Happy hosting!