Before delving into Linux system administration, it is crucial to understand the file system structure and user management mechanisms. This guide will detail the Linux File System Hierarchy Standard (FHS) and user permission management.
Core Concepts of the Linux File System
Basic Features of the File System
There are several important features of the Linux file system to remember:
-
Filename Length Limit: Directory and file names cannot exceed 255 characters
-
Case Sensitivity: File.txt and file.txt are two different files
-
Everything is a File: In Linux, devices, processes, network connections, etc., all exist in the form of files
Path Representation Methods
There are two path representation methods in Linux:
Absolute Path
The complete path starting from the root directory /:
/home/user1/file1 /etc/passwd /usr/local/bin/program
Relative Path
The path relative to the current working directory:
# Currently in /home/user1 directory ./file1 # file1 in the current directory file1 # shorthand for ./ ../user2/file2 # file2 in the parent directory user2 # Currently in /home/user2 directory ../user1/file1 # Accessing file1 in user1 directory
Detailed Explanation of the File System Hierarchy Standard (FHS)
Linux follows the File System Hierarchy Standard, with the main directory structure as follows:
Core System Directories
/ # Root directory, the starting point of the entire file system ├── bin/ # Basic command binaries (for regular users) ├── sbin/ # System management commands (for administrators) ├── boot/ # System boot files, kernel, and boot programs ├── dev/ # Device file directory │ └── null # System "trash can", discards output data ├── etc/ # System and software configuration files ├── proc/ # Virtual file system, kernel and process information └── tmp/ # Temporary file storage
User-Related Directories
/root/ # Home directory for the root user /home/ # Home directories for regular users └── username/ # Personal directory for a specific user
System Program Directories
/usr/ # System programs and files ├── bin/ # User program binaries ├── sbin/ # System management programs ├── local/ # Locally installed software ├── lib/ # 32-bit library files └── lib64/ # 64-bit library files
Variable Data Directories
/var/ # Stores frequently changing files ├── log/ # System and application logs ├── mail/ # Mail storage └── lib/ # Application database files /media/ # Automatically mounted removable devices /mnt/ # Manual mount points
Basic File Management Operations
File and Directory Operations
# Create a file touch filename.txt # Copy files/directories cp source_file destination_file cp -r source_dir destination_dir # Recursively copy directories # Move/Rename mv old_name new_name mv file_path new_location/ # Create a directory mkdir directory_name mkdir -p parent/child/grandchild # Create multi-level directories # Delete files/directories rm filename rm -rf directory_name # Force delete directory and contents
File Type Identification
Use ls -la to view detailed file information; the file type is indicated by the first character:
-rw-r--r-- # - indicates a regular file drwxr-xr-x # d indicates a directory brw-rw---- # b indicates a block device file crw-rw-rw- # c indicates a character device file srw-rw-rw- # s indicates a socket file prw-r--r-- # p indicates a pipe file lrwxrwxrwx # l indicates a symbolic link
View detailed file type information:
file /etc/hosts # Output: /etc/hosts: ASCII text
Text Editor Usage Guide
Vi/Vim Editor
Vi is the default text editor in Linux systems, mastering basic operations is very important:
Basic Mode Switching
vi filename # Open file and enter command mode i # Enter insert mode Esc # Return to command mode
Cursor Movement Commands
# Basic directional movement k # Move up j # Move down h # Move left l # Move right # Word-level movement w # Next word's beginning e # Current/next word's end b # Previous word's beginning # In-line movement ^ # Line's beginning $ # Line's end
Edit and Save Commands
dd # Delete current line u # Undo last operation :line_number # Jump to specified line :wq # Save and exit :q! # Force exit without saving
Nano Editor
For beginners, nano provides a more user-friendly interface:
# Install nano yum -y install nano # Use nano to edit a file nano filename
Nano’s common shortcut keys are displayed at the bottom of the screen, such as Ctrl+O to save, Ctrl+X to exit.
Linux User Management System
Viewing User Information
# View current user information id # Output: uid=1000(username) gid=1000(username) groups=1000(username) # View specified user information id username # View currently logged-in users who # View system processes ps aux | less
User Account Files
User information in Linux is stored in the following files:
-
/etc/passwd – Basic user information
-
/etc/shadow – User password information (stored encrypted)
User Creation and Management
Adding Users
# Basic user creation useradd username # Advanced user creation (specifying detailed parameters) useradd -u 1020 \
# Specify user ID -g 1001 \
# Specify primary group ID -c "Test User" \
# Add comment -d /home/test1 \
# Specify home directory -s /bin/bash \
# Specify default shell -G games \
# Specify additional groups test1 # Username
Parameter Explanation:
-
-u : Specify User ID (UID)
-
-g : Specify Primary Group ID (GID)
-
-c : Add user description
-
-d : Specify user home directory path
-
-s : Specify user default shell
-
-G : Specify user additional groups
-
-r : Create a system user
Privilege Escalation and Switching
# Temporarily elevate privileges to execute a command sudo command # Switch to root user sudo su # Switch to specified user su username
Configuring Sudo Privileges
Edit the sudoers file to configure user sudo privileges:
# Use visudo command for safe editing visudo # Or directly edit the file (not recommended) vi /etc/sudoers
Add configurations in the sudoers file:
# Allow user to execute all commands username ALL=(ALL) ALL # Allow user group to execute specific commands %groupname ALL=(ALL) /bin/ls, /bin/cat
Special Nature of the Root User
The root user is the super administrator of the Linux system:
-
UID of 0: This is the unique identifier for the root user
-
Unlimited Privileges: Can perform any system operation
-
System Security: Use root privileges cautiously to avoid accidental operations
Practical Recommendations and Summary
-
Principle of Least Privilege: Only grant users the minimum necessary privileges
-
Avoid Direct Use of Root: Use sudo to elevate privileges for administrative tasks
-
Regularly Review User Accounts: Remove unnecessary accounts and update permission settings
-
Possible Professional Directions for Further Study: System Administration, Network Security, CTF Competitions, DevOps
-
Continue learning to achieve proficiency in navigating the Linux file system and effectively managing files and directories
-
Understand and configure user permissions to safely perform system administration tasks
The structure of the Linux file system and user management is a core foundation of system administration. The file system hierarchy standard provides a clear framework for system organization, while the user management system ensures the security of the system and the orderly operation of a multi-user environment.