Examples
sudo systemctl start httpd to start apache web service,
can also use restart
sudo systemctl stop httpd stops the service
sudo systemctl enable httpd enables it to start at
system startup
sudo systemctl disable httpd disables it
sudo systemctl status httpd tells you if it is
running
possible services are in 1 of 3 directories in this order of
priority
the /etc/systemd/system directory ,
the /run/systemd/services directory and
the /lib/systemd/system directory.
So ls-l those directories to see units that systemctl
can
control.
### Important Update: systemctl list-unit-files will list
all available units and show if they are disabled or enabled. A powerful
tool indeed
systemctl list-units will only show active units, handy
but less output than the previous command.
package managers will install units to /lib/systemd/system If you
write you own units put them in /etc/systemd/system so they wont be
overwritten
by package managers.
Nefarious programs can hijack system.d and cron to autostart their systems. The following may be a help in finding them.
`systemctl list-unit-files –type=service
To see what services exist on the host If a service looks suspicious
then systemctl status suspicious.service andsystemctl cat
suspicious.service
Pay close attention to the ExecStart section. It shows you the actual binary or script being launched. A service named system-update.service means nothing if ExecStart points to a random script in /tmp. To check the timeline of events for that service, look at the journal:
journalctl -u suspicious.service
You can then systemctl stop and systemctl disable it if desired
Timers deserve a separate check because they can trigger another unit on a schedule. List them all with:
systemctl list-timers --all
If you spot an unfamiliar timer, trace the target unit it triggers to see what code it actually runs. ### 3. Check Cron Jobs
Cron requires checking a few different places. Start with the current user:
crontab -l
If you have admin access, check other user accounts:
crontab -u username -l
Then, check system-wide cron locations:
/etc/crontab
/etc/cron.d/
/etc/cron.daily/
/etc/cron.hourly/
/etc/cron.weekly/
/etc/cron.monthly/
If a cron entry points to a script, open that script and read through it without running it. Follow what it launches next, including other scripts, binaries, or external connections.