Why Choose a Linux Server?

In the world of the Internet, Linux servers are everywhere. From personal blogs to large enterprise systems, Linux has become the preferred operating system for servers due to its stability, security, and open-source nature. It is lightweight, efficient, and highly customizable, making it ideal for beginners to get started with server management.

1. Preparation for Installing a Linux Server

1.1 Download the Linux ISO Image

Choose a beginner-friendly distribution. Recommended options include:
- Ubuntu Server (e.g., 20.04 LTS)
- CentOS Stream (more enterprise-oriented)

1.2 Create a Bootable USB

Use a USB flash drive or external hard drive to create a bootable USB with one of these tools:
- Windows: Rufus (https://rufus.ie/)
- Mac/Linux: Use the dd command:

  sudo dd if=/path/to/ubuntu.iso of=/dev/sdb bs=4M status=progress

Replace /path/to/ubuntu.iso and /dev/sdb with your actual file path and device name.

1.3 Boot into the Installation Interface

Insert the bootable USB into the server. During startup, press F12 or DEL to enter the BIOS/UEFI, then select the USB as the boot device.

2. Steps to Install Linux Server

2.1 Start Installation

  1. Language, Timezone, Keyboard:
    - Default: English
    - Timezone: e.g., Asia/Shanghai
    - Keyboard layout: us (default)

  2. Disk Partitioning (Beginner-friendly):
    - Option 1: Use “Use an entire disk” (automatic partitioning).
    - Option 2: Manual partitioning (recommended for learning):

    • /boot: 200MB (boot partition for kernel files)
    • /: Remaining space (root partition for system files)
    • swap: 1.5x your RAM (swap partition, similar to Windows virtual memory)
  3. User Setup:
    - Username: yourname (e.g., admin)
    - Password: Remember this! Required for login.
    - Check “Install OpenSSH server” (critical for remote management).

  4. Click “Install Now” and wait (5-10 minutes).

2.2 Log In After Installation

After installation, reboot and select the Linux system (Ubuntu/CentOS Stream). Log in with your username and password to access the command-line interface (terminal).

3. Basic Configuration: Making the Server “Usable”

3.1 Network Setup: Connect to the Internet

  1. Check IP Address:
    - Ubuntu: ip addr (or ifconfig; install net-tools if needed: sudo apt install net-tools).
    - CentOS: ip addr (pre-installed).
    - Look for inet in the output (e.g., 192.168.1.100).

  2. Set Static IP (Avoid IP changes after reboot):
    - Ubuntu (Netplan):
    Edit config: sudo nano /etc/netplan/00-installer-config.yaml
    Example:

     network:
       ethernets:
         enp0s3:  # Check interface name with `ip addr`
           dhcp4: no
           addresses: [192.168.1.100/24]
           gateway4: 192.168.1.1
           nameservers:
             addresses: [8.8.8.8, 114.114.114.114]
       version: 2
 Apply changes: `sudo netplan apply`
  • CentOS (NetworkManager):
    Edit config: sudo vi /etc/sysconfig/network-scripts/ifcfg-ens33
    Example:
     ONBOOT=yes
     BOOTPROTO=static
     IPADDR=192.168.1.100
     NETMASK=255.255.255.0
     GATEWAY=192.168.1.1
     DNS1=8.8.8.8
 Restart network: `sudo systemctl restart network`
  1. Test Network:
    Run ping www.baidu.com. A successful response (e.g., “64 bytes from…”) confirms connectivity.

3.2 Package Management: Install Software

Linux uses package managers. Remember these commands:

  • Ubuntu/Debian (using apt):
  • Update package list: sudo apt update
  • Install software: sudo apt install 软件名 (e.g., sudo apt install vim)
  • Upgrade system: sudo apt upgrade

  • CentOS/RHEL (using yum or dnf):

  • Install software: sudo yum install 软件名 (e.g., sudo yum install wget)
  • Upgrade system: sudo yum update

3.3 User & Permissions: Secure Management

  1. Create a Non-Root User (Critical for Security):
   sudo useradd -m -s /bin/bash newuser  # -m: create home dir; -s: set shell
   sudo passwd newuser                   # Set password
   sudo usermod -aG sudo newuser         # Grant sudo privileges
  1. Switch Users:
    - Run commands as root: sudo 命令 (e.g., sudo apt update).
    - Switch to root: sudo su (enter password when prompted).

  2. Disable Root Login Directly (Security Best Practice):
    Edit SSH config: sudo nano /etc/ssh/sshd_config
    Set:

   PermitRootLogin no  # Disable root login
   PasswordAuthentication yes  # Allow password login (optional)

Restart SSH: sudo systemctl restart sshd (Ubuntu/CentOS).

3.4 Firewall: Protect the Server

  1. Ubuntu (using ufw):
    - Check status: sudo ufw status
    - Allow SSH (port 22): sudo ufw allow ssh
    - Allow HTTP/HTTPS: sudo ufw allow 80/tcp and sudo ufw allow 443/tcp
    - Enable firewall: sudo ufw enable

  2. CentOS (using firewalld):
    - Check status: sudo systemctl status firewalld
    - Allow port 22 (SSH): sudo firewall-cmd --add-port=22/tcp --permanent
    - Reload rules: sudo firewall-cmd --reload

4. Summary & Next Steps

You’ve now set up a basic Linux server: it connects to the internet, installs software, allows SSH remote access, and secures user permissions. Next steps:

  • Web Server: Deploy Nginx/Apache
  • Database: Set up MySQL/PostgreSQL
  • Containers: Learn Docker for application deployment

Tip: Troubleshoot by checking logs in /var/log/ or searching online (e.g., “Ubuntu 20.04 install Docker”). Practice is the fastest way to master Linux!

Xiaoye