A Linux service is the program that runs in the background, waiting to be used or carrying out essential tasks. For example the Apache server has a demon called httpd that listens on port 80 on your computer and when it receives a request for a page it sends the appropriate data back to the client machine.
Many services are required to rull all the time however many can be safely turned off for both security reasons as runninf unnecessary services opens more doors into your computer, but also for performance reasons.
It may not make much difference but your computer should boot slightly faster with less services it has to start on boot.
One of the techniques in every Linux adminstrator’s toolbox to improve security of box is to turn off unneeded services.
Below are two commands used to control services.
service – It is used starting and stopping of services during a session. If you start Apache with this command it will continue to run on next reboot and it will not start automatically.
chkconfig – It controls which services are set to start on boot, by their name these setting saved and are applied at next boot. Changing these settings will not start the service immediately. It will just flag them to be start from the next boot.
Commands used for maintaining a service.
To check the status of a service.
# service nameoftheservice status
TO start a service.
# service nameoftheservice start
To stop a service
# service nameoftheservice stop
To reload a service
# service nameoftheservice reload
To restart a service
# service nameoftheservice restart
Commands used for service availability.
To check availability of service
# chkconfig --list
To make the service available after reboot
# chkconfig service on
To make service unavailable after reboot
# chkconfig service off
Check status of SSH service (sshd).
# service sshd status openssh-daemon (pid 1974) is running...
To Stop SSH service
# service sshd stop Stopping sshd: [ OK ]
To start SSH Service
# service sshd start Starting sshd: [ OK ]
Reload service may be required after doing some changes in config file.
# service sshd reload Reloading sshd: [ OK ]
To restart any service required when reload doesn’t work.
# service sshd restart Stopping sshd: [ OK ] Starting sshd: [ OK ]
Check status of the all service availability.
# chkconfig --list abrt-ccpp 0:off 1:off 2:off 3:on 4:off 5:on 6:off abrtd 0:off 1:off 2:off 3:on 4:off 5:on 6:off acpid 0:off 1:off 2:on 3:on 4:on 5:on 6:off atd 0:off 1:off 2:off 3:on 4:on 5:on 6:off auditd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
To check perticular service
# chkconfig --list httpd httpd 0:off 1:off 2:off 3:off 4:off 5:off 6:off
To make service availability on for httpd
# chkconfig httpd on # chkconfig --list httpd httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
To make service availability off for httpd
# chkconfig httpd off # chkconfig --list httpd httpd 0:off 1:off 2:off 3:off 4:off 5:off 6:off
To make service httpd availability on only run level 5
# chkconfig --level 5 httpd on # chkconfig --list httpd httpd 0:off 1:off 2:off 3:off 4:off 5:on 6:off
The same can be done for making service unavailable in a particular run level.