1. Introduction to Linux
Linux is a free-to-use and freely distributed Unix-like operating system. It is a multi-user, multi-tasking operating system based on POSIX and UNIX that supports multi-threading and multi-CPU. Linux can run major UNIX tools, applications, and network protocols. It supports 32-bit and 64-bit hardware. Linux inherits Unix's network-centric design philosophy and is a stable multi-user network operating system.
1.1 History of Linux
The history of Linux dates back to 1991, when Linus Torvalds, a student at the University of Helsinki in Finland, began developing a free Unix-like operating system kernel. His goal was to create an operating system that could run on personal computers and that could be freely modified and distributed.
The development of the Linux kernel has received contributions from developers around the world, who collaborate through the Internet to continuously improve and refine the Linux kernel. Over time, Linux has evolved into a mature operating system widely used in servers, personal computers, embedded devices, and other fields.
1.2 Features of Linux
- Free and open-source: Linux is open-source software, and users can freely view, modify, and distribute the source code.
- Multi-user and Multi-tasking: Linux supports multiple users using the system simultaneously and can run multiple programs at the same time.
- Stability: Linux systems are very stable and can run for long periods without needing to restart.
- Security: Linux has powerful security mechanisms, including user permission management, file permission control, and more.
- Customizability: Users can customize Linux systems according to their needs.
- Wide Hardware Support: Linux supports various hardware devices, including servers, personal computers, embedded devices, and more.
- Rich Software: Linux has a large number of free software that can meet various needs.
2. Linux Distributions
Linux distributions are complete operating systems based on the Linux kernel, including the Linux kernel, various system tools, applications, and documentation. Different Linux distributions are optimized for different user groups and using scenarios, and users can choose the appropriate distribution according to their needs.
2.1 Major Linux Distributions
2.1.1 Ubuntu
Ubuntu is one of the most popular Linux distributions. It is based on Debian and is known for its user-friendliness and stability. Ubuntu is suitable for beginners and desktop users, offering rich software and good hardware support.
2.1.2 CentOS
CentOS is a free distribution based on Red Hat Enterprise Linux (RHEL). It is known for its stability and security. CentOS is suitable for server environments and is widely used in enterprise applications.
2.1.3 Debian
Debian is a stable and secure Linux distribution known for its strict package management and high-quality software. Debian is suitable for users who value stability and server environments.
2.1.4 Fedora
Fedora is a community distribution sponsored by Red Hat. It is known for its latest software and technologies. Fedora is suitable for users and developers who like to try new technologies.
2.1.5 Arch Linux
Arch Linux is a lightweight and flexible Linux distribution known for its simplicity, modernity, and user control. Arch Linux is suitable for experienced Linux users and uses a rolling release model to always stay up-to-date.
2.2 How to Choose a Linux Distribution
When choosing a Linux distribution, consider the following factors:
- User Experience: Beginners can choose user-friendly distributions like Ubuntu or Linux Mint; experienced users can choose more flexible distributions like Arch Linux or Gentoo.
- Usage Scenario: Desktop users can choose Ubuntu or Fedora; server users can choose CentOS or Debian; embedded device users can choose OpenWrt or Yocto Project.
- Stability Requirements: Users who need a stable system can choose Debian or CentOS; users who prefer the latest software can choose Fedora or Arch Linux.
- Software Support: Users who need specific software should choose a distribution that supports that software well.
- Community Support: Choose a distribution with an active community to get help when encountering problems.
3. Linux Installation
The Linux installation process varies by distribution, but the basic steps are similar. This section uses Ubuntu as an example to introduce the Linux installation process.
3.1 Pre-installation Preparation
- Backup Data: Before installing Linux, ensure you back up important data to prevent data loss in case of unexpected situations.
- Download ISO Image: Download the Ubuntu ISO image file from the official website.
- Create Installation Media: Use tools like Rufus or Etcher to write the ISO image to a USB drive or DVD.
- Check System Requirements: Ensure your computer meets Ubuntu's system requirements.
3.2 Installation Process
1. Insert the installation USB drive, restart the computer, and boot from the USB drive. 2. Select "Install Ubuntu" in the boot menu. 3. Choose language, click "Continue". 4. Choose keyboard layout, click "Continue". 5. Choose installation type: - For new computers, select "Erase disk and install Ubuntu". - For computers with existing operating systems, select "Install Ubuntu alongside them". - For advanced users, select "Something else" to customize partitions. 6. Choose time zone, click "Continue". 7. Create user account, set username and password, click "Continue". 8. Wait for installation to complete, then restart the computer. 9. Remove the installation USB drive, boot into the newly installed Ubuntu system.
3.3 Post-installation Configuration
After installation, some basic configurations are needed:
3.3.1 Update System
sudo apt update && sudo apt upgrade
3.3.2 Install Common Software
# Install common tools sudo apt install git curl wget vim # Install multimedia codecs sudo apt install ubuntu-restricted-extras # Install browsers sudo apt install firefox chromium-browser # Install office software sudo apt install libreoffice
3.3.3 configuration Firewall
# Enable firewall sudo ufw enable # Check firewall status sudo ufw status # Allow SSH connections sudo ufw allow ssh # Allow HTTP and HTTPS connections sudo ufw allow http sudo ufw allow https
4. Linux Basic Concepts
4.1 Linux System Structure
Linux system consists of the following parts:
- Kernel: The core of the Linux system, responsible for managing hardware resources, process scheduling, memory management, etc.
- Shell: Command line interpreter, through which users interact with the kernel.
- File System: Structure for storing files and directories.
- System Tools: Such as text editors, file management tools, etc.
- Applications: Various software used by users.
4.2 Linux File System Hierarchy
Linux uses a standard File System Hierarchy (FHS), with main directories including:
- /: Root directory, the starting point for all files and directories.
- /bin: Basic command binary files.
- /sbin: System administration command binary files.
- /etc: System configuration files.
- /home: User home directories.
- /root: Root user home directory.
- /var: Variable files, such as logs, mail, etc.
- /tmp: Temporary files.
- /usr: User programs and data.
- /lib: Library files.
- /mnt: Mount points.
4.3 Linux Users and Groups
Linux is a multi-user system, each user has a unique user ID (UID) and username. Users can belong to one or more groups, and groups have unique group IDs (GID) and group names.
- Regular Users: Users with limited permissions, UID usually greater than 1000.
- System Users: Users used to run system services, UID usually less than 1000.
- Root User: User with all system permissions, UID is 0.
5. Practice Case: Installing Ubuntu Server
5.1 Case Objective
Install Ubuntu Server 20.04 LTS, configure basic services, and prepare for subsequent server applications.
5.2 Implementation Steps
5.2.1 Pre-installation Preparation
- 1. Download Ubuntu Server 20.04 LTS ISO image.
- 2. Create installation USB drive.
- 3. Prepare server hardware, ensuring it meets system requirements.
5.2.2 Installation Process
1. Boot the server from the USB drive. 2. Select language: English. 3. Select keyboard layout: English (US). 4. Select installation type: Ubuntu Server. 5. configuration network: Set static IP address or use DHCP. 6. configuration proxy: If needed, set proxy server. 7. configuration Ubuntu archive mirror: Use default value. 8. configuration store: Select automatic partitioning or manual partitioning. 9. Set up user: Create username and password. 10. Install SSH server: Select "Install OpenSSH server". 11. Select additional software: Choose as needed. 12. Wait for installation to complete, then restart the server.
5.2.3 Post-installation Configuration
5.2.3.1 Update System
sudo apt update && sudo apt upgrade -y
5.2.3.2 Install Common Tools
sudo apt install -y git curl wget vim htop net-tools
5.2.3.3 configuration Firewall
sudo ufw enable sudo ufw allow ssh sudo ufw status
5.2.3.4 configuration SSH
# Edit SSH configuration file sudo vim /etc/ssh/sshd_config # Modify the following configuration # Port 22 # Can be changed to other port # PermitRootLogin no # Disable root remote login # PasswordAuthentication yes # Allow password authentication # Restart SSH service sudo systemctl restart ssh
5.3 Running Effect
After installation, the server will run Ubuntu Server 20.04 LTS system, which can be managed through SSH remote connection. The server has been configured with basic security measures and can start deploying various services, such as web servers, database servers, etc.
6. Interactive Exercises
Exercise 1: Choose the Appropriate Linux Distribution
Based on the following scenarios, choose the appropriate Linux distribution and explain why:
- 1. A beginner wants to install Linux on a home computer, mainly for daily office work and entertainment.
- 2. An enterprise needs to deploy a web server, requiring the system to be stable and secure.
- 3. A developer needs a development environment with the latest software.
- 4. An advanced user wants a highly customizable Linux system.
Exercise 2: Install Ubuntu Desktop Edition
Install Ubuntu Desktop Edition according to the following steps:
- 1. Download Ubuntu Desktop Edition ISO image.
- 2. Create installation USB drive.
- 3. Install Ubuntu, choosing to coexist with existing operating systems.
- 4. After installation, update the system and install common software.
After installation, record the problems encountered during the installation process and their solutions.
Exercise 3: Explore Linux File System
In the installed Linux system, perform the following operations:
- 1. View all directories under the root directory.
- 2. View configuration files under the /etc directory.
- 3. View user home directories under the /home directory.
- 4. View log files under the /var/log directory.
Record the main content and purpose of each directory.