How to Start a Service in Linux: Simple Commands Explained
To start a service in Linux, use the
systemctl start service-name command on modern systems with systemd. On older systems, you can use service service-name start. Replace service-name with the actual service you want to start.Syntax
The basic syntax to start a service depends on your Linux system's init system.
- systemctl start <service-name>: Starts the service using systemd, the modern init system.
- service <service-name> start: Starts the service using the older SysV init system.
Replace <service-name> with the name of the service you want to start, like nginx or ssh.
bash
systemctl start <service-name> service <service-name> start
Example
This example shows how to start the ssh service using systemctl. It demonstrates the command and the expected output when checking the service status.
bash
sudo systemctl start ssh sudo systemctl status ssh --no-pager
Output
● ssh.service - OpenBSD Secure Shell server
Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2024-06-07 10:00:00 UTC; 5s ago
Main PID: 1234 (sshd)
Tasks: 1 (limit: 4915)
Memory: 2.0M
CGroup: /system.slice/ssh.service
└─1234 /usr/sbin/sshd -D
Common Pitfalls
Common mistakes when starting services include:
- Not using
sudoor root privileges, which are required to start most services. - Using the wrong command for your system's init system (e.g., using
serviceon a system with systemd). - Typos in the service name causing "Unit not found" errors.
- Trying to start a service that is disabled or not installed.
Always check the service name and your permissions before starting.
bash
sudo service ssh start # Older systems sudo systemctl start ssh # Modern systems
Quick Reference
| Command | Description |
|---|---|
| systemctl start | Start a service on systemd-based systems |
| service | Start a service on SysV init systems |
| sudo systemctl status | Check the status of a service |
| sudo systemctl enable | Enable service to start on boot |
| sudo systemctl stop | Stop a running service |
Key Takeaways
Use
systemctl start service-name on modern Linux systems to start services.Older Linux systems may require
service service-name start instead.Always run service start commands with
sudo or as root.Check the service name carefully to avoid errors.
Use
systemctl status service-name to verify the service is running.