start, stop, restart Linux services (daemon HUNTING!!) // Linux for Hackers // EP 6
Demons in Linux: What Are They?
Introduction to Daemons
- The speaker introduces the concept of "demons" (or daemons) in Linux, emphasizing that they are essential background services that keep the system running.
- This episode is part of a series aimed at teaching Linux skills, focusing on managing these daemons and understanding their role.
Learning Objectives
- Viewers are encouraged to participate by setting up their own Linux environment or using a provided free lab from Hack The Box Academy.
- Hack The Box Academy offers resources for learning hacking skills, including training for IT professionals.
Getting Started with Linux
- The speaker prompts viewers to engage with the content by liking and subscribing, while preparing their Linux setup for practical learning.
- Instructions are given on accessing the course material related to service and process management within Hack The Box Academy.
Understanding Processes in Linux
Definition of Processes
- A process is defined as an instance of a running program; launching applications like Sublime Text creates corresponding processes.
Demonstrating Process Management
- Viewers are guided through using terminal commands to view active processes, illustrating how opening and closing programs affects process visibility.
- The command
ps auxis introduced as a method to list all current processes, demonstrating its utility in filtering results based on specific applications like Sublime Text.
Interactive vs. Background Processes
- An explanation is provided about interactive processes—those initiated by user action—and how they cease when the application is closed.
- Examples include editing files with Nano; when closed, associated processes disappear from the list shown by terminal commands.
Understanding Daemons in Linux
What are Daemons?
- Daemons are background processes that operate independently of user interaction, performing essential tasks without direct control from users.
- Similar to Windows services, daemons manage various functions such as networking and printing on Linux systems. They are crucial for system operations.
- A daemon can be identified by a 'd' at the end of its name (e.g.,
sshdfor SSH daemon), indicating its role as a background service.
Finding and Managing Daemons
- The command
ps aux | grep sshis used to locate the SSH daemon running in the background, demonstrating how these processes function without user intervention.
- Another example is the NTP daemon (
ntpd), which keeps time synchronized on Linux servers. Identifying these daemons helps understand their roles in system management.
Mastering Daemon Management
- Users need to learn how to manage daemons effectively, as this knowledge is vital for Linux administration or hacking activities.
- The term "daemon" has roots in Greek mythology, referring to a neutral supernatural being rather than an evil entity, which explains its use in computing contexts.
Systemd: The Master Daemon
- Systemd serves as the master daemon responsible for starting, stopping, and managing all other daemons on a Linux system. It plays a critical role during the boot process.
- As both a service manager and initialization system, Systemd ensures that necessary services are operational when the system starts up.
Visualizing Process Management
- When booting up a Linux system, Systemd initializes all other processes through a method called "forking," allowing users to interact with their systems immediately after startup.
- Using the command
pstree, one can visualize Systemd as the first process (PID 1), illustrating how it branches out into other processes upon booting.
Controlling Services with Systemctl
- To manage daemons effectively, users utilize
systemctl, a command-line tool designed for controlling services managed by Systemd.
- While there are alternative init systems like SysV Init and Upstart historically used in some distributions, Systemd has become predominant across modern Linux distros.
Understanding Systemd and Managing Daemons
Introduction to Systemd and Units
- The speaker introduces the concept of managing daemons using systemd, referring to them as "units" instead of the traditional term "daemons."
- Emphasizes that while this terminology may seem confusing, it is essential for understanding how systemd operates.
Basic Commands for Managing SSH Daemon
- Demonstrates how to stop the SSH daemon (sshd) using the command
systemctl stop sshd, with a warning about being logged out if connected via SSH.
- Advises using
sudobefore commands to ensure proper permissions when managing services.
Checking Daemon Status
- Introduces checking the status of a daemon with
systemctl status sshd, indicating whether it is active or inactive.
- Shows how to start the sshd service again with
systemctl start sshdand confirms its active status afterward.
Restarting and Reloading Services
- Explains restarting a service with
systemctl restart sshd, which stops and then starts the service again.
- Mentions an alternative command for reloading configurations without stopping services, noting that not all daemons support this feature.
Enabling and Disabling Services at Boot
- Discusses configuring services to start automatically at boot using
systemctl enable ntpor prevent them from starting withsystemctl disable ntp.
- Verifies changes in service status by checking if NTP is disabled but still running currently.
Quick Status Checks for Services
- Introduces quick commands like
is-activeandis-enabledto check if a service is running or set to start on boot.
Listing All Active Daemons
- Describes how to list all active units (daemons/services) using
systemctl list-units, clarifying that these are referred to as units in systemd terminology.
- Highlights that each unit has a type designation (e.g.,
.service) which helps identify its function within systemd.
Understanding System Services and Daemons
Overview of Active Services
- The discussion begins with a focus on managing services, specifically using the command
systemctl list unitsto filter for active services.
- Key terms are defined: "unit" refers to the daemon's name, "load" indicates if it's loaded in memory, and "active" shows whether it is currently running.
Troubleshooting Daemon Issues
- A scenario is presented where the Nginx daemon is not enabled. The speaker emphasizes the importance of understanding how to manage daemons when they do not behave as expected.
- Attempts to locate Nginx using
systemctl list unitsyield no results because it only lists active daemons.
Listing All Units
- To find inactive daemons like Nginx, the command
systemctl list-unit-filesis introduced, which reveals that Nginx is disabled.
- The status command (
sudo systemctl status nginx) confirms that Nginx is neither active nor enabled.
Enabling and Starting Nginx
- Steps are outlined to enable and start the Nginx service: first enabling it with
sudo systemctl enable nginx, then attempting to start it withsudo systemctl start nginx.
- An error occurs when starting Nginx; however, systemd provides guidance on checking its status.
Checking Logs for Errors
- The speaker uses
journalctl -xeto check logs but finds no entries, indicating a potential issue with the journal daemon itself.
- To resolve this, they identify and restart the journal daemon using
sudo systemctl restart systemd-journald.
Final Troubleshooting Steps
- After restarting the journal service, an attempt to start Nginx again leads to another failure due to port 80 being occupied by another service.
- The logs provide insights into why Nginx cannot start, highlighting that effective management of daemons requires familiarity with both their statuses and any conflicts present.
How to Hunt Demons in Linux
Overview of Demon Hunting Techniques
- The speaker introduces the concept of "hunting demons" in Linux, indicating that this video will focus on mastering techniques related to this topic.
- Key skills mentioned include masking and targeting, which are essential for effectively managing demons within the Linux environment.
- An extended version of the video is available on a learning website, encouraging viewers to explore further into the subject matter.
Learning Resources and Sponsorship
- The speaker promotes Hack The Box Academy as a sponsor, highlighting their new business offerings and lab resources available for users.
- Acknowledgment of personal caffeine consumption suggests an energetic presentation style, enhancing viewer engagement.
Engagement with Viewers
- Encouragement for viewers to interact with content by liking, subscribing, and commenting is emphasized as part of ethical engagement with YouTube's algorithm.
- Mention of a free membership option that provides access to ad-free videos; there’s also a paid membership available for those who wish to support the channel financially.
Conclusion and Viewer Interaction
- The speaker invites feedback from viewers about the video content and expresses gratitude towards those who continue watching until the end.