April 8, 2019
3 min Read
April 8, 2019
3 min Read
Managing a Linux VPS is a critical and sometimes very difficult task if you don’t have the right tools. Often the difficulty lies in having to configure and maintain many resources and services. On a server, most resources are software making them a little easier to monitor. In this tutorial, you’ll learn all the Linux service basics, including how to manage, control, and list services in Linux.
A service is a program that runs in the background outside the interactive control of system users as they lack an interface. This in order to provide even more security, because some of these services are crucial for the operation of the operating system.
On the other hand, in systems like Unix or Linux, the services are also known as daemons. Sometimes the name of these services or daemons ends with the letter d. For example, sshd is the name of the service that handles SSH.
So, let us start to work and list services in Linux.
Let’s look at a potential scenario. While running your Linux system, you can no longer access localhost. Chances are that the HTTP service was disabled, and causing the problem.
To troubleshoot issues like this one and many others, it’s good to know how to list all services in Linux.
Fortunately, CentOS and Ubuntu – two of the most popular operating systems in their areas – share systemd. That means that the commands we are going to present are compatible with both systems.
First, we have to connect to our server using SSH. If you’re having trouble, check out our PuTTY tutorial.
Once inside, we need to be the root user to list service in Linux.
Now we can list all services in Linux. To do it, run the command:
sudo systemctl list-unit-files --type service --all
When the command is run, we will see all the services that are on the system. However, we will also see that some have a defined status. Let’s learn what all these mean.
In case we want to know only the services that are active, we have to use a command together with grep, like so:
sudo systemctl | grep running
Now it is time to learn how to manage a specific service. Note that each service represents software that works differently. In this tutorial, we will only show how to start, check the status of and stop services – the basic controls
To start a service on Linux, we need to run the following command:
sudo systemctl start [service_name]
If the service is correctly configured, it will start. Now, if we want to stop it, we will use the following command:
sudo systemctl stop [service_name]
Meanwhile, to check the status of a service we can use:
sudo systemctl status [service_name]
It is also possible to have a service run while the operating system is being loaded:
sudo systemctl enable [service_name]
Or remove it from the initial load:
sudo systemctl disable [service_name]
Finally, it is possible to verify which port is being used by a service. For this, we will use netstat.
To install it on Ubuntu, we just run:
sudo apt install netstat-nat
If we are using CentOS 7:
yum install net-tools
Then, we run the following command:
sudo netstat -plnt
The output will give us all the required network information.
Learning how to list services in Linux is easy and can greatly speed up troubleshooting! In this tutorial, we learned how to start, enable, disable, stop, and list all services in Linux! Now you can manage your Linux VPS like a pro.
Finally, we recommend you to read more about systemctl to learn all the in-depth uses. Happy developing!