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
- You need to start, stop, or restart a service (e.g. after changing its config)
- You want a service to start automatically when the system boots
- You want to see whether a service is running and read its recent messages
- You're troubleshooting why something (SSH, web server, etc.) isn't working
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
- Use
systemctl status servicenamefirst when something isn't working—it shows state and recent errors - Remember:
enable/disableaffect boot;start/stopaffect the current run - Service names on Ubuntu are often the program or package name (e.g.
ssh,nginx,apache2,cron); uselist-units --allto find the exact name - After changing a unit file, run
sudo systemctl daemon-reloadbeforestartorrestart
Common Mistakes to Avoid
- Forgetting
sudowhen starting, stopping, enabling, or disabling—you'll get "Permission denied" or similar - Confusing
enable(start at boot) withstart(start now) - Using the full filename (e.g.
ssh.service) when the short name (ssh) works and is simpler - Editing unit files and then starting the service without running
daemon-reloadfirst
Best Practices
- Use
systemctl stopandsystemctl start(orrestart) instead ofkillfor services - Check
statusafter starting or restarting to confirm the service is running and healthy - Enable only services you need at boot to keep startup fast and reduce exposure
- Use
reloadinstead ofrestartwhen the service supports it and you only changed config