Building a Linux server starts with selecting the right distribution for your intended workload. If you are wondering How To Build A Linux Server from scratch, this guide walks you through every step with clear, practical instructions. Whether you need a file server, web server, or media server, the process is straightforward once you understand the basics.
First, decide what your server will do. A home media server needs different software than a production web server. Your choice of Linux distribution affects everything from package management to security updates. For beginners, Ubuntu Server or Debian are excellent choices because they have large communities and extensive documentation.
How To Build A Linux Server
Before you start, gather your hardware. You can use an old desktop, a dedicated server from a hosting provider, or a virtual machine. The minimum requirements are modest: a 64-bit processor, 1GB of RAM, and 10GB of disk space. For better performance, aim for 4GB of RAM and a solid-state drive.
Choose Your Linux Distribution
Your distribution determines the package manager and default tools. Here are popular options:
- Ubuntu Server – User-friendly, large community, LTS versions supported for 5 years
- Debian – Stable, minimal bloat, great for production
- CentOS Stream – RHEL-based, good for enterprise environments
- Fedora Server – Cutting-edge packages, ideal for development
- openSUSE Leap – Stable with excellent administration tools
For this guide, we use Ubuntu Server 22.04 LTS because it balances ease of use with reliability. Download the ISO image from the official website and create a bootable USB drive using tools like Rufus (Windows) or dd (Linux/Mac).
Install The Operating System
Boot from the USB drive. You will see a menu with installation options. Select “Install Ubuntu Server” and follow these steps:
- Choose your language and keyboard layout
- Configure network interface – DHCP is fine for initial setup
- Set a hostname – something like “myserver” or “fileserver”
- Create a user account with a strong password
- Select “Install OpenSSH server” when prompted – this allows remote access
- Choose “Use entire disk” for partitioning unless you have specific needs
- Wait for the installation to complete, then reboot
After reboot, log in with your username and password. You should see a command prompt. Congratulations, you have a basic Linux server.
Initial Server Configuration
Now we harden and prepare the server. Run these commands as root or with sudo:
sudo apt update && sudo apt upgrade -y
This updates all packages. Next, install essential tools:
sudo apt install curl wget git ufw -y
Configure the firewall to allow SSH connections only:
sudo ufw allow OpenSSH
sudo ufw enable
Check the firewall status with sudo ufw status verbose. You should see OpenSSH allowed.
Set Up Static IP Address
Servers need a static IP so clients can always find them. Edit the netplan configuration file:
sudo nano /etc/netplan/00-installer-config.yaml
Replace the contents with (adjust for your network):
network:
ethernets:
ens33:
dhcp4: no
addresses:
- 192.168.1.100/24
gateway4: 192.168.1.1
nameservers:
addresses: [8.8.8.8, 8.8.4.4]
version: 2
Apply the changes: sudo netplan apply. Test by pinging an external site: ping google.com.
Enable Remote Access With SSH
SSH is already installed. For better security, disable root login and use key-based authentication:
sudo nano /etc/ssh/sshd_config
Find these lines and change them:
PermitRootLogin noPasswordAuthentication no(after setting up keys)
Generate an SSH key pair on your client machine: ssh-keygen -t ed25519. Copy the public key to the server: ssh-copy-id username@server-ip. Restart SSH: sudo systemctl restart sshd.
Install Server Roles
Now add the software your server needs. Here are common roles:
Web Server (Apache or Nginx)
For Apache: sudo apt install apache2 -y
For Nginx: sudo apt install nginx -y
Allow HTTP and HTTPS in firewall: sudo ufw allow 'Apache Full' or sudo ufw allow 'Nginx Full'. Test by visiting your server’s IP in a browser.
Database Server (MySQL/MariaDB)
sudo apt install mariadb-server -y
Run secure installation: sudo mysql_secure_installation. Set a root password and remove anonymous users.
File Server (Samba)
sudo apt install samba -y
Create a shared directory: sudo mkdir /srv/share
Edit Samba config: sudo nano /etc/samba/smb.conf. Add:
[Share] path = /srv/share browseable = yes read only = no guest ok = yes
Restart Samba: sudo systemctl restart smbd. Allow Samba in firewall: sudo ufw allow samba.
Media Server (Plex or Jellyfin)
For Plex, add the repository: curl https://downloads.plex.tv/plex-keys/PlexSign.key | sudo apt-key add -
Then install: sudo apt install plexmediaserver -y. Access via browser at port 32400.
Monitor System Health
Keep an eye on resources with these tools:
htop– Interactive process viewerdf -h– Disk usagefree -h– Memory usagejournalctl -xe– System logsnetstat -tulpn– Open ports
Install htop: sudo apt install htop -y. Run it to see CPU and memory usage in real time.
Automate Updates
Enable automatic security updates:
sudo apt install unattended-upgrades -y
sudo dpkg-reconfigure --priority=low unattended-upgrades
Choose “Yes” when prompted. This keeps your server patched without manual intervention.
Backup Your Configuration
Backup critical files regularly. Use rsync to copy to an external drive or cloud storage:
rsync -avz /etc/ /backup/etc-backup/
For databases, use mysqldump: mysqldump -u root -p --all-databases > /backup/all-databases.sql. Schedule backups with cron: crontab -e and add 0 2 * * * /path/to/backup-script.sh.
Secure Your Server Further
Security is ongoing. Here are additional steps:
- Install fail2ban to block brute-force attacks:
sudo apt install fail2ban -y - Use a non-standard SSH port (e.g., 2222) to reduce scanning
- Enable automatic security updates as above
- Disable unused services:
sudo systemctl disable service-name - Regularly review logs:
sudo tail -f /var/log/auth.log
Common Troubleshooting Tips
If something breaks, check these first:
- Cannot connect via SSH? Verify SSH service is running:
sudo systemctl status sshd - Web server not responding? Check firewall rules:
sudo ufw status - Disk full? Use
du -sh /*to find large files - Service won’t start? View logs:
journalctl -u service-name
Remember to reboot after major changes: sudo reboot. Always test in a non-production environment first.
Frequently Asked Questions
What Is The Best Linux Distribution For A Beginner Server?
Ubuntu Server is the most beginner-friendly due to its extensive documentation and community support. Debian is also good if you prefer stability over cutting-edge features.
Can I Build A Linux Server On Old Hardware?
Yes, Linux runs efficiently on older machines. A 10-year-old PC with 2GB RAM and a dual-core processor can serve files or run a small website without issues.
How Do I Access My Linux Server Remotely?
Use SSH from any terminal: ssh username@server-ip. Ensure port 22 is open in your firewall and router port forwarding is configured if accessing from outside your network.
Do I Need A Static IP For My Server?
Yes, a static IP makes it easier for clients to connect. Most home routers allow you to reserve an IP address via DHCP reservation in the router settings.
How Often Should I Update My Linux Server?
Enable automatic security updates for critical patches. Manually check for updates weekly using sudo apt update && sudo apt upgrade. Reboot after kernel updates.
Building a Linux server is a rewarding project that gives you full control over your infrastructure. Start with a simple setup, then expand as you learn. The skills you gain apply to cloud servers, home labs, and enterprise environments. Keep your system updated, monitor logs, and back up data regularly. With practice, you will be able to deploy and manage servers confidently.