Use dmesg, journalctl, and tail -f /var/log/syslog to check Linux logs—these commands instantly reveal hardware errors, service crashes, or authentication failures. For deeper troubleshooting, combine them with filters like grep or awk. Below, we break down the exact steps, common pitfalls, and how to interpret log messages without confusion.

What You'll Need

  • A terminal with root or sudo privileges (most commands require elevation)
  • Basic familiarity with Linux commands (e.g., ls, cd)
  • The specific log file or service you’re troubleshooting (e.g., /var/log/auth.log for authentication)
  • Optional: grep or awk for parsing logs (included by default on most distros)

Step-by-Step: How to Check Linux Logs

  1. Identify the log type. Linux logs are stored in various files and sysems:
    • Kernel logs (hardware/driver issues): /var/log/dmesg or dmesg
    • System logs (general errors/startup): /var/log/syslog
    • Authentication logs (failed logins): /var/log/auth.log (Ubuntu/Debian) or /var/log/secure (RHEL/CentOS)
    • Application logs (e.g., Apache/Nginx): Check service-specific directories like /var/log/apache2/
    • (modern distros): journalctl (replaces older syslog on many systems)

    Note: Paths vary slightly by distro. Use find /var/log -type f -name "*.log" to locate all logs.

  2. Check kernel logs for hardware issues (run as root):
    sudo dmesg | grep -i error

    This filters for errors in the kernel ring buffer. For real-time monitoring:

    sudo tail -f /var/log/kern.log

    Replace kern.log with dmesg if the file doesn’t exist.

  3. Inspect system-wide logs with journalctl (systemd distros only):
    journalctl -xe
    • -x: Show expanded output with explanations
    • -p 3: Filter for errors (priority 3)
    • --since "2024-01-01": Limit to a date range

    For a specific service (e.g., nginx):

    journalctl -u nginx --no-pager
  4. Read traditional syslog files (older distros):
    cat /var/log/syslog | grep -i "failed"

    Common syslog files:

    • /var/log/auth.log (Ubuntu/Debian): Failed logins, sudo attempts
    • /var/log/secure (RHEL/CentOS): Similar to auth.log
    • /var/log/messages: General system events
  5. Tail logs in real-time (for ongoing issues):
    sudo tail -f /var/log/auth.log

    Use Ctrl+C to exit. Add | grep "service_name" to filter (e.g., sudo tail -f /var/log/nginx/error.log | grep 500).

  6. Search logs for keywords:
    grep "permission denied" /var/log/syslog

    For recurring issues, combine with awk:

    grep "error" /var/log/nginx/error.log | awk '{print $1, $2}' | sort | uniq -c

    This counts errors by date/time.

  7. Check logs for a specific service:
    systemctl status apache2

    Then inspect its log directory (e.g., /var/log/apache2/error.log). For systemd services:

    journalctl -u .service
  8. Archive old logs (optional):
    sudo logrotate /etc/logrotate.conf

    Most distros auto-rotate logs, but verify with ls -l /var/log/.

Common Mistakes

  • Ignoring log timestamps: Always check the date/time of errors. A 2023 log won’t help a 2024 issue.
  • Assuming all logs are in /var/log: Application logs (e.g., Docker, PostgreSQL) may be elsewhere (e.g., /var/lib/docker/containers/).
  • Overlooking permissions: You’ll get Permission denied if checking logs without sudo. Always use sudo unless the file is readable by your user.
  • Not filtering logs: Raw log files are overwhelming. Use grep, journalctl -p 3, or tail -n 50 to focus on critical lines.
  • Assuming syslog exists on all systems: Modern distros (e.g., Ubuntu 22.04+) rely on journalctl. Check with which journalctl.
  • Copy-pasting errors without context: A single log line may not explain the issue. Read 5–10 lines before and after for root cause.

Tips for Effective Log Checking

  • Use less for interactive browsing:
    sudo less /var/log/syslog

    Navigate with arrow keys; press / to search, q to quit.

  • Set up log monitoring alerts:
    sudo journalctl --no-pager | grep -m 1 "CRITICAL"

    Add to cron for daily checks:

    0 3 * * * sudo grep "error" /var/log/syslog >> /tmp/log_errors.txt
  • Check logs remotely with SSH:
    ssh user@server "sudo journalctl -u nginx --no-pager"
  • Correlate logs with processes:
    ps aux | grep nginx
            sudo journalctl -u nginx --since "2024-01-01 08:00:00"

    Match the process ID in logs to active services.

  • Use logwatch for automated summaries (install via package manager):
    sudo apt install logwatch
            sudo logwatch --service all
  • Document recurring errors: Create a text file (e.g., /root/log_issues.md) to track patterns over time.

Troubleshooting: When Logs Don’t Help

If logs show nothing useful or the issue persists:

  1. Check system resources:
    top
            free -h
            df -h

    Low memory, disk space, or CPU can mask errors in logs.

  2. Test with a minimal environment:
    sudo systemctl isolate multi-user.target

    Reboot into a text-only mode to rule out GUI-related issues.

  3. Update the system:
    sudo apt update && sudo apt upgrade -y

    Bugs may be fixed in newer kernel/logging packages.

  4. Reinstall the problematic service:
    sudo apt purge nginx && sudo apt install nginx

    Replace nginx with your service name. This clears corrupted configs.

  5. Check for conflicting services:
    systemctl list-units --type=service --state=failed

    Failed services may hijack ports or resources.

  6. Isolate the issue:
    sudo journalctl --list-boots

    Compare logs from a working boot to a failing one:

    sudo journalctl -b -1 --no-pager
  7. Enable debugging for the service:
    sudo nginx -T | grep debug

    For Apache, edit /etc/apache2/apache2.conf and add:

    LogLevel debug

    Then restart the service.

  8. Check hardware:
    sudo smartctl -a /dev/sda

    Replace /dev/sda with your disk. Disk errors often appear in kernel logs but may not be logged elsewhere.

Frequently Asked Questions

How do I check logs for a specific user?

Use grep with the username in auth logs:

sudo grep "user_name" /var/log/auth.log

For systemd journals:

journalctl -u sshd --user=username

Why do my logs show "kernel panic" but no errors?

A kernel panic halts the system before logging. Reboot and check:

dmesg | grep -i "panic\|oom"

Look for Out of Memory (OOM) killer messages or driver crashes. Enable CONFIG_PANIC_TIMEOUT=0 in the kernel config to prevent automatic reboots for debugging.

Can I redirect logs to a remote server?

Yes, use rsyslog or syslog-ng:

sudo apt install rsyslog
sudo nano /etc/rsyslog.conf

Add:

*.* action(type="omfwd" Target="remote_log_server" Port="514" Protocol="tcp")

Restart rsyslog:

sudo systemctl restart rsyslog

How do I clear old logs?

Use logrotate (automatic) or manually:

sudo rm /var/log/syslog
sudo touch /var/log/syslog
sudo chmod 640 /var/log/syslog

For journalctl, clear with:

sudo journalctl --vacuum-time=7d

This retains logs for 7 days.

What’s the difference between dmesg and journalctl?

dmesg shows kernel messages from the ring buffer (hardware/driver events). journalctl captures all systemd logs (services, users, etc.). Use dmesg for hardware issues; journalctl for software/services.

How do I check logs for a specific time range?

For journalctl:

journalctl --since "2024-01-01 08:00" --until "2024-01-01 09:00"

For syslog:

sudo grep "error" /var/log/syslog | grep -E "Jan  1 08|Jan  1 09"

Use --since and --until with dates/times in journalctl.