Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Linux Services Management Guide (Focused & Practical)
- =====================================================
- ----------------------------------------
- Join our telegram channel
- https://t.me/LinuxClassesEFXTv
- ----------------------------------------
- This guide helps you manage and troubleshoot Linux services using systemd and legacy tools, with a real-world example (CUPS service on port 631).
- ----------------------------------------
- GENERAL SERVICE MANAGEMENT
- ----------------------------------------
- List all services (enabled, disabled, static):
- ----------------------------------------------
- sudo systemctl list-unit-files --type=service --all
- List active (running) services:
- -------------------------------
- sudo systemctl list-units --type=service
- Check detailed status of a specific service:
- --------------------------------------------
- sudo systemctl status [service_name]
- Start a service:
- ----------------
- sudo systemctl start [service_name]
- Stop a service:
- ---------------
- sudo systemctl stop [service_name]
- Restart a service:
- ------------------
- sudo systemctl restart [service_name]
- Reload service configuration:
- -----------------------------
- sudo systemctl reload [service_name]
- Enable a service to start at boot:
- ----------------------------------
- sudo systemctl enable [service_name]
- Disable a service from starting at boot:
- ----------------------------------------
- sudo systemctl disable [service_name]
- Mask a service (blocks manual & automatic starts):
- --------------------------------------------------
- sudo systemctl mask [service_name]
- Unmask a service:
- -----------------
- sudo systemctl unmask [service_name]
- List failed services:
- ---------------------
- systemctl --failed
- Show service dependencies:
- --------------------------
- systemctl list-dependencies [service_name]
- Check service startup time impact:
- ----------------------------------
- systemd-analyze blame
- Legacy service commands (SysVinit compatible):
- ----------------------------------------------
- sudo service [service_name] start
- sudo service [service_name] stop
- sudo service [service_name] restart
- sudo service [service_name] status
- ----------------------------------------
- PORT-RELATED SERVICE TROUBLESHOOTING
- ----------------------------------------
- Find which process is using a specific port:
- --------------------------------------------
- sudo fuser -v [port]/tcp
- Check which ports are open:
- ----------------------------
- sudo netstat -tulnp
- # OR
- ss -tuln
- Scan for a specific port:
- --------------------------
- sudo nmap -p [port] localhost
- ----------------------------------------
- DISABLING & BLOCKING A SERVICE (CUPS Example)
- ----------------------------------------
- 1. Stop the service:
- --------------------
- sudo service cups stop
- 2. Disable at boot (SysV method):
- ---------------------------------
- sudo update-rc.d -f cupsys remove
- 3. Disable with systemd:
- ------------------------
- sudo systemctl disable cups
- 4. Mask the service (to fully block it):
- ----------------------------------------
- sudo systemctl mask cups
- 5. Reboot and confirm it's closed:
- ----------------------------------
- sudo reboot
- sudo nmap -p 631 localhost
- If port 631 is STILL active after reboot:
- 6. Repeat post-boot cleanup:
- ----------------------------
- sudo systemctl unmask cups.service
- sudo service cups start
- sudo service cups status
- sudo service cups stop
- sudo systemctl disable cups
- sudo systemctl mask cups
- sudo nmap localhost
- sudo reboot
- sudo nmap localhost
- ----------------------------------------
- REMINDERS
- ----------------------------------------
- - Masked services are completely blocked from starting.
- - Use `fuser` or `netstat` to identify what is keeping a port open.
- - After disabling services, always reboot or reload configurations to apply changes.
- - Avoid disabling essential system services unless you're certain.
- ----------------------------------------
- #Linux #SysAdmin #ServiceManagement #Systemd #Ports #CUPS #Troubleshooting
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement