How to install Debian on a server

How to Install Debian on a Server Debian stands as one of the most stable and reliable Linux distributions, making it an excellent choice for server deployments. Whether you're setting up a web server, database server, or enterprise infrastructure, Debian's robust architecture and extensive package repository provide the foundation for virtually any server application. This comprehensive guide will walk you through the entire process of installing Debian on a server, from initial planning to post-installation configuration. Why Choose Debian for Server Deployment Debian has earned its reputation as a preferred server operating system for several compelling reasons: - Stability and Reliability: Debian's rigorous testing process ensures packages are thoroughly vetted before release - Security: Regular security updates and a dedicated security team maintain system integrity - Package Management: APT (Advanced Package Tool) provides efficient software installation and dependency resolution - Hardware Support: Extensive hardware compatibility across various server architectures - Long-term Support: Stable releases receive support for several years - Free and Open Source: No licensing costs or restrictions Pre-Installation Planning System Requirements Before beginning the installation process, verify your server meets Debian's minimum requirements: Minimum Requirements: - RAM: 512 MB (1 GB recommended for server workloads) - Storage: 10 GB available disk space (20+ GB recommended) - Processor: Any x86-64 compatible CPU - Network: Ethernet adapter for network connectivity Recommended Server Specifications: - RAM: 4 GB or more depending on intended services - Storage: 50+ GB with consideration for future growth - Multiple network interfaces for redundancy - Hardware RAID controller for data protection Choosing the Right Debian Version Debian offers three main branches: 1. Stable: Most suitable for production servers, thoroughly tested 2. Testing: Contains newer packages but may have stability issues 3. Unstable: Latest packages, not recommended for servers For server installations, always choose the Stable branch to ensure maximum reliability and security. Download Options Visit the official Debian website (debian.org) to download the installation media: - Network Install (netinst): Small ISO that downloads packages during installation - Complete Installation Sets: Full DVD images with all packages - Cloud Images: Pre-configured images for cloud platforms For most server installations, the netinst ISO is recommended as it ensures you get the latest packages during installation. Creating Installation Media USB Installation Media Create a bootable USB drive using your preferred method: Linux/macOS: ```bash Identify your USB device lsblk Write the ISO to USB (replace /dev/sdX with your USB device) sudo dd if=debian-12.0.0-amd64-netinst.iso of=/dev/sdX bs=4M status=progress ``` Windows: Use tools like Rufus or balenaEtcher to create bootable USB media from the Debian ISO file. Network Boot (PXE) For enterprise environments, consider setting up PXE boot for automated installations across multiple servers. BIOS/UEFI Configuration Before starting the installation: 1. Boot Priority: Set USB or optical drive as the primary boot device 2. Secure Boot: Disable Secure Boot if using UEFI (Debian supports it, but may cause complications) 3. RAID Configuration: Configure hardware RAID arrays if applicable 4. Network Boot: Enable PXE boot if using network installation Step-by-Step Installation Process Initial Boot and Language Selection 1. Boot from Installation Media: Insert your USB drive and restart the server 2. Select Installation Method: Choose "Install" for text-based installation or "Graphical Install" for GUI 3. Language Selection: Choose your preferred language (affects installer and default system language) 4. Location Selection: Select your country/region for timezone and mirror configuration 5. Keyboard Layout: Configure keyboard mapping for your hardware Network Configuration Network setup is crucial for server installations: 1. Network Interface Selection: Choose primary network interface 2. Network Configuration Method: - DHCP: Automatic configuration (suitable for initial setup) - Manual: Static IP configuration (recommended for servers) Manual Network Configuration Example: ``` IP Address: 192.168.1.100 Netmask: 255.255.255.0 Gateway: 192.168.1.1 DNS Servers: 8.8.8.8, 8.8.4.4 ``` 3. Hostname Configuration: Enter a descriptive hostname (e.g., "web-server-01") 4. Domain Name: Specify your domain (e.g., "company.local") User Account Setup 1. Root Password: Set a strong root password or leave blank to disable root login 2. User Account Creation: Create a regular user account with sudo privileges 3. Username and Password: Choose secure credentials for the user account Disk Partitioning Disk partitioning is critical for server performance and maintenance: Guided Partitioning Options 1. Use Entire Disk: Simple option for single-disk servers 2. Use Entire Disk with LVM: Recommended for flexibility 3. Use Entire Disk with Encrypted LVM: Enhanced security option Manual Partitioning (Recommended for Servers) Create a custom partition scheme: ``` /boot - 500 MB (ext4) / - 20 GB (ext4) /var - 10 GB (ext4) /home - 5 GB (ext4) /tmp - 2 GB (ext4) swap - 4 GB (swap) /var/log - 5 GB (ext4) remaining - LVM (for future expansion) ``` Benefits of Manual Partitioning: - Isolates system components - Prevents log files from filling root partition - Enables targeted backup strategies - Facilitates system maintenance Package Selection The installer will present software selection options: Recommended Server Selections: - Standard System Utilities: Essential command-line tools - SSH Server: Remote access capability - Web Server: If hosting web applications - Print Server: Only if print services required Avoid Installing: - Desktop Environment (GNOME, KDE, etc.) - Games and entertainment packages - Unnecessary services that increase attack surface Bootloader Installation 1. GRUB Installation: Install GRUB bootloader to the primary disk 2. Boot Device Selection: Choose the correct disk for bootloader installation 3. Multiple OS Consideration: Configure for dual-boot scenarios if applicable Post-Installation Configuration Initial System Update After successful installation and first boot: ```bash Update package lists sudo apt update Upgrade installed packages sudo apt upgrade -y Install essential packages sudo apt install curl wget vim htop tree unzip -y ``` SSH Configuration Secure SSH access for remote administration: ```bash Edit SSH configuration sudo vim /etc/ssh/sshd_config ``` Recommended SSH Security Settings: ``` Port 2222 # Change default port PermitRootLogin no # Disable root login PasswordAuthentication no # Use key-based authentication AllowUsers yourusername # Restrict user access ``` Restart SSH service: ```bash sudo systemctl restart ssh ``` Firewall Configuration Configure UFW (Uncomplicated Firewall): ```bash Install and enable UFW sudo apt install ufw -y sudo ufw enable Configure basic rules sudo ufw default deny incoming sudo ufw default allow outgoing sudo ufw allow 2222/tcp # SSH on custom port sudo ufw allow 80/tcp # HTTP sudo ufw allow 443/tcp # HTTPS ``` System Monitoring Setup Install monitoring tools: ```bash System monitoring sudo apt install htop iotop nethogs -y Log monitoring sudo apt install logwatch -y System information sudo apt install neofetch -y ``` Automatic Updates Configuration Configure unattended upgrades for security updates: ```bash Install unattended-upgrades sudo apt install unattended-upgrades -y Configure automatic updates sudo dpkg-reconfigure -plow unattended-upgrades ``` Security Hardening Fail2Ban Installation Protect against brute-force attacks: ```bash Install Fail2Ban sudo apt install fail2ban -y Create local configuration sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local Edit configuration sudo vim /etc/fail2ban/jail.local ``` System Auditing Enable system auditing: ```bash Install audit daemon sudo apt install auditd -y Enable and start service sudo systemctl enable auditd sudo systemctl start auditd ``` Troubleshooting Common Issues Installation Problems Issue: Network Configuration Fails - Verify network cable connections - Check DHCP server availability - Try manual IP configuration - Ensure network interface is recognized Issue: Disk Partitioning Errors - Verify disk health with manufacturer tools - Check RAID configuration - Ensure sufficient disk space - Try different partitioning schemes Issue: Package Download Failures - Verify internet connectivity - Try different Debian mirrors - Check firewall settings - Ensure DNS resolution works Boot Problems Issue: System Won't Boot After Installation - Verify GRUB installation on correct disk - Check boot order in BIOS/UEFI - Try recovery mode from GRUB menu - Reinstall bootloader if necessary GRUB Rescue Commands: ```bash List available partitions ls Set root partition set root=(hd0,1) Load kernel linux /vmlinuz root=/dev/sda1 initrd /initrd.img Boot system boot ``` Network Issues Issue: No Network Connectivity After Installation ```bash Check network interface status ip addr show Restart networking service sudo systemctl restart networking Check network configuration cat /etc/network/interfaces Test DNS resolution nslookup google.com ``` Performance Issues Issue: Slow System Performance - Check available RAM: `free -h` - Monitor CPU usage: `top` or `htop` - Check disk I/O: `iotop` - Review system logs: `journalctl -f` Best Practices for Server Installation Documentation - Document all configuration changes - Maintain installation notes for future reference - Create system diagrams showing network configuration - Keep hardware specifications recorded Backup Strategy - Plan backup strategy before going into production - Test restore procedures - Document backup and recovery processes - Consider automated backup solutions Monitoring and Maintenance - Set up system monitoring from day one - Configure log rotation - Plan regular maintenance windows - Establish update procedures Security Considerations - Implement defense in depth - Regular security updates - Monitor system logs - Use configuration management tools Conclusion Installing Debian on a server provides a solid foundation for reliable, secure server operations. The process, while straightforward, requires careful planning and attention to detail. By following this comprehensive guide, you'll have a properly configured Debian server ready for production workloads. Remember that server installation is just the beginning. Ongoing maintenance, security updates, monitoring, and backup procedures are essential for long-term success. Consider documenting your specific configuration choices and creating standardized installation procedures for consistent deployments across your infrastructure. The stability and extensive package ecosystem of Debian make it an excellent choice for servers ranging from small business applications to enterprise-scale deployments. With proper installation and configuration, your Debian server will provide years of reliable service while maintaining the security and performance standards required for critical business operations. Whether you're deploying a single server or planning a large-scale infrastructure rollout, the principles and procedures outlined in this guide will help ensure successful Debian server installations that meet your organization's requirements for reliability, security, and performance.