CIS120 Linux Fundamentals by Scott Shaper

systemctl Basics

Think of systemctl as the control panel for system services. Just as you might use a remote to turn a TV on or off or change channels, systemctl lets you start, stop, restart, and check the status of services. It also lets you enable or disable services so they start (or don't start) automatically when the computer boots. Most systemctl commands that change something—like starting or stopping a service—require root privileges, so you'll often use sudo systemctl. This lesson covers the basics you need for everyday use on an Ubuntu Server system.

Quick Reference

Command What It Does Common Use
systemctl start name Start a service Starting a web server or other service
systemctl stop name Stop a service Stopping a service cleanly
systemctl restart name Restart a service Applying config changes or recovering from a problem
systemctl status name Show service status and recent log Checking if a service is running or why it failed
systemctl enable name Enable service to start at boot Making a service start automatically
systemctl disable name Disable service from starting at boot Stopping a service from auto-starting
systemctl list-units --type=service List loaded services Seeing what services are running

Note: Starting, stopping, enabling, and disabling services usually require root. Use sudo systemctl .... Checking status often works without sudo.

When to Use systemctl

Starting, Stopping, and Restarting Services

You use the service name (without .service) with systemctl. On Ubuntu Server, common service names include ssh (SSH server), nginx or apache2 (web server), and cron (scheduled tasks). You can say systemctl start ssh and systemd will find the matching unit (e.g. ssh.service).

Command What It Does When to Use It
start Start the service now When the service isn't running and you want it to run
stop Stop the service When you want to shut it down cleanly
restart Stop and then start the service After changing config or to "reset" the service
reload Reload config without full restart When the service supports reloading config without dropping connections

Practical Examples

# Start the SSH service (on Ubuntu the service is named ssh)
sudo systemctl start ssh

# Stop a service
sudo systemctl stop nginx

# Restart a service (e.g. after editing its config file)
sudo systemctl restart nginx

# Reload config without stopping the service (if supported)
sudo systemctl reload nginx

Checking Service Status

systemctl status servicename shows whether the service is running, stopped, or failed, and prints a few recent log lines. You usually don't need sudo to run status.

Status Examples

# Check if SSH service is running (on Ubuntu the service is named ssh)
systemctl status ssh

# Check a service by full name
systemctl status nginx.service

# Status shows: active (running), inactive (dead), failed, etc.
# It also shows recent log output for that service

Enabling and Disabling Services (Start at Boot)

"Enable" means "start this service when the system boots into its default target." "Disable" means "don't start it at boot." Enabling or disabling doesn't start or stop the service right now—it only affects what happens at the next boot. You often need sudo to enable or disable.

Command What It Does When to Use It
enable Start this service at boot When you want the service to run whenever the system starts
disable Don't start this service at boot When you don't want it to auto-start
is-enabled name Show whether the service is enabled Checking if a service will start at boot

Enable and Disable Examples

# Enable SSH to start at boot (on Ubuntu the service is named ssh)
sudo systemctl enable ssh

# Disable a service from starting at boot
sudo systemctl disable nginx

# Check if a service is enabled
systemctl is-enabled ssh
# Output: enabled  or  disabled

Listing Services

To see which services exist and whether they're running, use systemctl list-units. You can filter by type (e.g. only services) and by state (e.g. only active).

Command What It Does When to Use It
list-units --type=service List loaded service units See what services are currently loaded
list-units --type=service --all List all service units (including inactive) Find a service name or see everything installed
list-unit-files --type=service List unit files and enable state See which services are enabled at boot

Listing Examples

# List currently loaded/active services
systemctl list-units --type=service

# List all service units (active and inactive)
systemctl list-units --type=service --all

# List service unit files and whether they're enabled
systemctl list-unit-files --type=service

# Filter with grep (e.g. find ssh)
systemctl list-units --type=service --all | grep ssh

Tips for Success

Common Mistakes to Avoid

Best Practices