Linux 111: Troubleshooting and Debugging Techniques
Welcome back! Even the most reliable Linux systems can run into issues — a service that won’t start, slow performance, or strange network behavior. This article introduces essential troubleshooting and debugging techniques to help you identify and resolve problems efficiently.
Start with the Basics
Begin by checking overall system health. These simple commands can give you a quick overview:
uptime
— See how long the system has been running and load averagesdf -h
— Check available disk spacefree -h
— View memory usagetop
orhtop
— Monitor running processes
Check System Logs
Logs are crucial for understanding what’s going wrong. Key tools and files include:
journalctl
— View system logs (Systemd-based systems)dmesg
— Check kernel messages, useful for hardware issues/var/log/
— Traditional log files likesyslog
,auth.log
, andmessages
sudo journalctl -xe
tail -f /var/log/syslog
Diagnosing Services
If a service isn’t running properly, these commands can help you troubleshoot:
sudo systemctl status nginx
sudo systemctl restart nginx
sudo systemctl enable nginx
Check related logs for deeper insight.
Debugging Network Issues
ping
— Test connectivityip a
— Display network interfaces and addressesss -tuln
— View open and listening portstraceroute
— Trace route to a host
ping 8.8.8.8
ip a
ss -tuln
Resource and Process Debugging
Identify resource-intensive processes and manage them effectively:
top
ps aux --sort=-%mem | head
kill -9 <PID>
Use strace
to trace system calls of a specific process:
strace -p <PID>
File Permission Issues
Permissions are a common source of problems. Use these commands to investigate and fix them:
ls -l
chmod +x script.sh
chown user:user file.txt
Debugging Shell Scripts
Use the -x
option to run a script in debug mode:
bash -x myscript.sh
Redirect output and error messages for analysis:
./myscript.sh > output.log 2>&1
Useful Debugging Tools
lsof
— List open filestcpdump
— Capture network trafficgdb
— GNU Debugger (for C/C++ programs)perf
— Performance analysis tools
Common Issues and Quick Fixes
- System won’t boot: Use a live CD, check GRUB and
/etc/fstab
. - Package manager locked: Remove lock files in
/var/lib/dpkg/lock
. - Permission denied errors: Double-check permissions, SELinux/AppArmor contexts.
Best Practices
- Document your troubleshooting steps
- Make one change at a time and test
- Keep backups of configuration files before editing
Wrapping Up
Mastering troubleshooting is about being methodical and using the right tools. Whether you’re debugging a broken script, a failing service, or a slow server, Linux provides powerful commands to guide you.
Next up: Linux 112: Linux Backup Strategies and Disaster Recovery