A service (also called a daemon) is a program that runs in the background, like a web server or an SSH server. Each running service can be a way into the machine, so an administrator needs to know which services are running and why. Practice on your own VM, from a snapshot.
What systemd and systemctl are
Most modern Linux systems use systemd to start and manage services. The tool you use to talk to it is systemctl. Services are described by “unit files” such as ssh.service, kept in /lib/systemd/system/ and /etc/systemd/system/.
A service has two separate states that beginners often mix up:
- Active or inactive: is it running right now?
- Enabled or disabled: will it start automatically at boot?
Looking at services
systemctl list-units --type=service --state=running # what is running now
systemctl list-unit-files --state=enabled # what starts at boot
systemctl status ssh # details for one service
The status output shows whether it is active, its process ID, and the last few log lines. For finding what is listening on the network, use:
sudo ss -tulpn
This lists open ports and which program owns each. Every listening port should have a reason to exist. If port 21 (FTP) or 23 (Telnet) is open on a machine that never needed them, that is a finding to investigate.
Starting, stopping and disabling
sudo systemctl start apache2 # start now
sudo systemctl stop apache2 # stop now
sudo systemctl restart apache2 # stop then start (after config changes)
sudo systemctl reload apache2 # re-read config without a full stop
sudo systemctl enable apache2 # start at boot
sudo systemctl disable apache2 # do not start at boot
sudo systemctl disable --now cups # disable and stop in one step
To really stop a service from coming back, you usually need both stop and disable. Stopping alone lasts only until the next reboot, and disabling alone leaves it running right now.
A stronger option is mask, which prevents a service from being started at all, even by another service. Use it sparingly and note that you did it: sudo systemctl mask servicename.
Deciding what to keep
The rule of thumb is least necessary service. Read your task or README. If it says the machine is a web server, keep the web server. Services that are commonly unneeded on a practice workstation include file-sharing daemons, print servers, and remote-access tools nobody asked for. But do not disable something critical: ssh may be required by the scenario, and disabling systemd-journald or networking would break the machine.
Before changing a service, check what it is with systemctl status name and apt show for the package. Change one thing at a time, then confirm the system still works. When a service that must stay is misbehaving, read its log:
journalctl -u ssh --since "1 hour ago"
Check your understanding
1. What is the difference between disable and stop?
- They are the same
- Stop ends it now; disable prevents it from starting at boot
- Disable deletes the program
- Stop prevents boot start
Answer: Stop ends it now; disable prevents it from starting at boot You often need both to fully turn off an unneeded service.
2. Which command shows which programs are listening on network ports?
- ls -la
- sudo ss -tulpn
- cd /etc
- apt list
Answer: sudo ss -tulpn It lists listening ports and the process that owns each.
3. After editing a service’s config file, which command makes it pick up changes?
- systemctl restart (or reload)
- systemctl mask
- apt autoremove
- chmod 777
Answer: systemctl restart (or reload) The service must re-read its configuration to apply the change.
4. What is the best rule for deciding whether to disable a service?
- Disable everything
- Keep only what the machine’s stated purpose needs
- Disable anything with a long name
- Never change services
Answer: Keep only what the machine’s stated purpose needs Unneeded services add risk, but required ones must keep running.
