CIS120 Linux Fundamentals by Scott Shaper

Understanding System Services

Think of system services like background workers in a building: the web server that serves pages, the SSH server that lets you log in remotely, or the scheduler that runs tasks at certain times. They are programs that run in the background, often from the moment the computer boots, and keep running until you shut the system down. When you use ps or top, many of the processes you see are these services. Understanding what they are and how the system manages them helps you see why certain programs are always running and how to control them properly. This lesson describes how services work on an Ubuntu Server system (and other systemd-based Linux systems).

Quick Reference

Term What It Means Common Use
Service (daemon) A long-running background program Web server, SSH, cron, database
Service manager Program that starts, stops, and monitors services systemd on most modern Linux systems
Unit A configuration file that describes a service (or other resource) Defines how and when a service runs
Target A group of units; like a "runlevel" (e.g. multi-user mode) What runs when the system boots normally

When This Matters

What Is a Service?

A service (also called a daemon) is a program that runs in the background. Unlike a command you run in the terminal—which runs, does something, and exits—a service keeps running. It usually has no window or terminal attached; it just does its job (accepting network connections, running scheduled tasks, and so on) until the system shuts down or someone stops it.

Common examples:

Service What It Does
ssh Lets you log in remotely via SSH
nginx or apache Web server that serves web pages
cron Runs commands on a schedule
systemd-logind Manages logins and sessions

How the System Manages Services

On most modern Linux systems, a program called systemd is the service manager. It is responsible for:

You don't usually run services by hand from the command line and then leave them in the background. Instead, you tell systemd to start or stop them using the systemctl command (covered in the next lesson). That way the system knows about them and can manage them correctly.

Units and Unit Files

systemd organizes everything into units. A unit is a "thing" that systemd can manage: a service, a mount point, a timer, and so on. Each unit is defined by a unit file—a configuration file that describes what to run and how.

For a service, the unit file might specify:

Unit files are stored in a few places:

Location What It's For
/usr/lib/systemd/system/ Units installed by packages (don't edit these)
/etc/systemd/system/ Local overrides and custom units (admin can edit)

Service unit files usually end in .service, for example ssh.service or nginx.service on Ubuntu. The name without the .service suffix is the unit name you use with systemctl (e.g. ssh, nginx).

Targets (Boot and Run States)

A target is a group of units. Think of it as a "mode" the system is in. When the system boots, it enters a default target (usually multi-user.target or graphical.target), and systemd starts all the units that belong to that target.

Target What It Means
multi-user.target Normal multi-user mode (text login, no desktop)
graphical.target Full desktop with graphical login
rescue.target Minimal single-user mode for recovery

When you "enable" a service, you're often saying "start this when the system reaches a certain target (e.g. multi-user)." The next lesson shows how to do that with systemctl.

Services and Processes

When you run ps aux or top, you see many processes. A lot of them are services started by systemd. They might run as the root user or as a dedicated user (e.g. www-data for a web server). So when you learn about processes (as in the ps and top lessons), you're already looking at the same programs that systemd manages—you're just viewing them from a different angle. systemctl is the right tool to start, stop, or enable them; kill can stop a process but doesn't tell systemd, so it's better to use systemctl stop for services.

Tips for Success

Common Mistakes to Avoid

Best Practices