1. Why Learn Linux Server Maintenance?¶
In the internet era, Linux has become the “main force” of servers—from websites and databases to cloud services, many critical systems run on Linux. It is stable, open-source, and secure, making it a must-have skill for operations and developers. For beginners, mastering basic Linux maintenance knowledge not only helps you understand server status but also solve simple issues like file permission problems or service startup failures.
2. Command Line: Linux’s “Language”¶
Linux servers are primarily operated through the command line (graphical interfaces are rarely used), much like “talking” to the computer. Don’t be intimidated—start with these fundamental commands:
- Log into the server: Use an SSH tool (e.g., Putty, Xshell, or the system’s built-in terminal) and run
ssh username@server-ip, then enter the password when prompted. - View current directory:
pwd(Print Working Directory), e.g., it will display/home/yourname. - Change directory:
cd target-path, e.g.,cd /etc(enter the system configuration directory),cd ~(return to the user’s home directory),cd ..(go up one level). - List files/directories:
ls(list). To show detailed info (permissions, size, etc.), usels -l; to show hidden files (those starting with.), usels -a.
3. File System: Linux’s “Room Layout”¶
Linux’s file system is like an inverted tree, with the root directory / at the top. All other directories branch from the root:
/root: Home directory for the root user (administrator)./home/username: Home directory for regular users (each user has their own space)./etc: Stores system configuration files (e.g., network, service, software settings)./var: Holds dynamic data (logs, cache, databases, e.g.,/var/logis the system log folder)./binand/usr/bin: Store system commands (e.g.,ls,cp).
Tip: The tree command visualizes directory structure (if not installed, ls works as a basic alternative).
4. File & Directory Operations: “Copy, Move, Delete”¶
File operations are the most frequent in daily maintenance—master these:
- Create empty file:
touch filename, e.g.,touch test.txt. - Create directory:
mkdir directory-name, e.g.,mkdir docs. - Copy files/directories:
cp source-file target-location, e.g.,cp test.txt /home/user/docs. To copy directories recursively, add-r:cp -r docs /tmp. - Move/rename:
mv source-file target-location, e.g.,mv test.txt docs/(move to thedocsdirectory); if the target is a new filename, it renames:mv test.txt new.txt. - Delete files/directories:
rm filename(add-rto delete directories, e.g.,rm -r docs). Note:rmis irreversible! Always back up or confirm first.
5. File Permissions: Who Can Read/Write/Execute?¶
Permissions are Linux’s core security mechanism, represented by rwx (read, write, execute). Each file/directory has 3 permission categories: owner, group, and others.
- Permission representation: For
rw-r--r--: - Owner:
rw-(readable and writable, not executable) - Group:
r--(readable only) - Others:
r--(readable only) - Numeric shorthand: Use numbers (r=4, w=2, x=1), e.g.,
rw-r--r--is644(4+2=6 for owner, 4 for group, 4 for others). - Modify permissions:
chmod [permissions] filename, e.g., add execute permission:chmod +x test.sh; or use numbers:chmod 755 test.sh(owner: rwx=7, group: rx=5, others: rx=5). - Change owner/group:
chown new-owner file,chgrp new-group file, e.g.,sudo chown root:root test.txt(change owner and group to root).
6. Processes & Services: What’s Running on the Server?¶
Programs running on servers are called “processes”—manage them with these commands:
- View processes:
ps(current terminal processes) orps -aux(all processes, more detailed);topfor real-time dynamic monitoring (pressqto exit). - Terminate processes:
kill process-id, e.g.,kill 1234; if it won’t stop, usekill -9 1234(forceful termination). - Manage services: Linux uses
systemctlto manage services (e.g., Nginx, MySQL). Common commands: sudo systemctl start/stop/restart/status service-name(e.g.,sudo systemctl restart nginx).
7. Network Configuration: How the Server Communicates¶
Server network connectivity is critical—learn these basics:
- Check IP address:
ip addr(view all network interfaces, look foreth0orens33);ifconfig(may requiresudo apt install net-toolsif missing). - Test network connectivity:
ping target-ip, e.g.,ping 8.8.8.8(test Google DNS). Unreachable issues may indicate firewall or network problems. - View open ports:
netstat -tuln(list all listening ports) orss -tuln(more efficient), e.g.,netstat -tuln | grep 80(check if port 80 is in use). - Open ports in firewall:
- Ubuntu/Debian:
sudo ufw allow 80/tcp(permanent),sudo ufw status(check status). - CentOS/RHEL:
sudo firewall-cmd --add-port=80/tcp --permanent,sudo firewall-cmd --reload(apply changes).
8. System Updates & Software Installation¶
Regularly update systems and install software:
- Update system:
- Ubuntu/Debian:
sudo apt update(refresh package list),sudo apt upgrade(install updates). - CentOS/RHEL:
sudo yum update(orsudo dnf update, recommended). - Install software:
- Ubuntu:
sudo apt install package-name(e.g.,sudo apt install nginx). - CentOS:
sudo yum install package-name(e.g.,sudo yum install httpd). - Uninstall software:
sudo apt remove package-name(Ubuntu) orsudo yum remove package-name(CentOS).
9. Logs & Backups: Troubleshooting & Data Security¶
- View logs: System logs are in
/var/log, e.g.,auth.log(login attempts),syslog(system events). Usetail -n 10 /var/log/auth.logto view the last 10 lines. - Backup files: Use
tarfor compression/backup, e.g.,tar -czf backup.tar.gz /home/user/docs(compressdocstobackup.tar.gz). Restore withtar -xzf backup.tar.gz.
10. Beginner Learning Tips¶
- Hands-on practice: Use a Linux VM (e.g., VMware, VirtualBox) or online platforms (e.g., Katacoda) to practice commands.
- Tools: Terminal: Xshell, FinalShell; File transfer: FileZilla; SSH: Putty.
- Seek help: Use
man command(e.g.,man ls) for documentation, or search errors on Baidu/Google. - Good habits: Backup before system changes, verify commands (e.g., add
-itormfor confirmation).
Linux server maintenance has no shortcuts—practice, troubleshoot, and summarize. You’ll find it “well-behaved” with consistent effort. Start with basic commands, and you’ll quickly become a skilled server maintainer!