Advertisement
efxtv

Linux Services Management Guide (Focused & Practical)

Jan 14th, 2024 (edited)
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.01 KB | Cybersecurity | 0 0
  1. Linux Services Management Guide (Focused & Practical)
  2. =====================================================
  3.  
  4. ----------------------------------------
  5. Join our telegram channel
  6. https://t.me/LinuxClassesEFXTv
  7. ----------------------------------------
  8.  
  9. This guide helps you manage and troubleshoot Linux services using systemd and legacy tools, with a real-world example (CUPS service on port 631).
  10.  
  11. ----------------------------------------
  12. GENERAL SERVICE MANAGEMENT
  13. ----------------------------------------
  14.  
  15. List all services (enabled, disabled, static):
  16. ----------------------------------------------
  17. sudo systemctl list-unit-files --type=service --all
  18.  
  19. List active (running) services:
  20. -------------------------------
  21. sudo systemctl list-units --type=service
  22.  
  23. Check detailed status of a specific service:
  24. --------------------------------------------
  25. sudo systemctl status [service_name]
  26.  
  27. Start a service:
  28. ----------------
  29. sudo systemctl start [service_name]
  30.  
  31. Stop a service:
  32. ---------------
  33. sudo systemctl stop [service_name]
  34.  
  35. Restart a service:
  36. ------------------
  37. sudo systemctl restart [service_name]
  38.  
  39. Reload service configuration:
  40. -----------------------------
  41. sudo systemctl reload [service_name]
  42.  
  43. Enable a service to start at boot:
  44. ----------------------------------
  45. sudo systemctl enable [service_name]
  46.  
  47. Disable a service from starting at boot:
  48. ----------------------------------------
  49. sudo systemctl disable [service_name]
  50.  
  51. Mask a service (blocks manual & automatic starts):
  52. --------------------------------------------------
  53. sudo systemctl mask [service_name]
  54.  
  55. Unmask a service:
  56. -----------------
  57. sudo systemctl unmask [service_name]
  58.  
  59. List failed services:
  60. ---------------------
  61. systemctl --failed
  62.  
  63. Show service dependencies:
  64. --------------------------
  65. systemctl list-dependencies [service_name]
  66.  
  67. Check service startup time impact:
  68. ----------------------------------
  69. systemd-analyze blame
  70.  
  71. Legacy service commands (SysVinit compatible):
  72. ----------------------------------------------
  73. sudo service [service_name] start
  74. sudo service [service_name] stop
  75. sudo service [service_name] restart
  76. sudo service [service_name] status
  77.  
  78. ----------------------------------------
  79. PORT-RELATED SERVICE TROUBLESHOOTING
  80. ----------------------------------------
  81.  
  82. Find which process is using a specific port:
  83. --------------------------------------------
  84. sudo fuser -v [port]/tcp
  85.  
  86. Check which ports are open:
  87. ----------------------------
  88. sudo netstat -tulnp
  89. # OR
  90. ss -tuln
  91.  
  92. Scan for a specific port:
  93. --------------------------
  94. sudo nmap -p [port] localhost
  95.  
  96. ----------------------------------------
  97. DISABLING & BLOCKING A SERVICE (CUPS Example)
  98. ----------------------------------------
  99.  
  100. 1. Stop the service:
  101. --------------------
  102. sudo service cups stop
  103.  
  104. 2. Disable at boot (SysV method):
  105. ---------------------------------
  106. sudo update-rc.d -f cupsys remove
  107.  
  108. 3. Disable with systemd:
  109. ------------------------
  110. sudo systemctl disable cups
  111.  
  112. 4. Mask the service (to fully block it):
  113. ----------------------------------------
  114. sudo systemctl mask cups
  115.  
  116. 5. Reboot and confirm it's closed:
  117. ----------------------------------
  118. sudo reboot
  119. sudo nmap -p 631 localhost
  120.  
  121. If port 631 is STILL active after reboot:
  122.  
  123. 6. Repeat post-boot cleanup:
  124. ----------------------------
  125. sudo systemctl unmask cups.service
  126. sudo service cups start
  127. sudo service cups status
  128. sudo service cups stop
  129. sudo systemctl disable cups
  130. sudo systemctl mask cups
  131. sudo nmap localhost
  132. sudo reboot
  133. sudo nmap localhost
  134.  
  135. ----------------------------------------
  136. REMINDERS
  137. ----------------------------------------
  138.  
  139. - Masked services are completely blocked from starting.
  140. - Use `fuser` or `netstat` to identify what is keeping a port open.
  141. - After disabling services, always reboot or reload configurations to apply changes.
  142. - Avoid disabling essential system services unless you're certain.
  143.  
  144. ----------------------------------------
  145. #Linux #SysAdmin #ServiceManagement #Systemd #Ports #CUPS #Troubleshooting
  146.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement