How to Use the chkconfig Command on Linux

While most systems use $systemctl to manage their services, older versions that rely on System V and Upstart rely on the $chkconfig command for the same task. Here’s how to use the chkconfig command on Linux.

The $chkconfig is a command used to manage services for each run level. Using the $chkconfig command, the user can display the service status of all processes and configure their start and stop points.

This guide will help you learn how to use the chkconfig command on Linux. We’ll cover the basics of the command, its syntax, and some examples of how to use it for different tasks.

Understanding the $chkconfig Command

$chkconfig refers to the utility of the Command Line Interface that’s responsible for configuring run levels for a specified service while ensuring it displays the services with their configurations.

Note: If you’re planning to use $chkconfig for anything other than listing, you will need root privileges.

The $chkconfig command can be used for a variety of purposes. A list of uses is given below.

  • To list existing services.
  • To enable a specific service within a run level.
  • To disable a specific service within a run level.
  • To display the startup configuration of a specific service.
  • To check whether a group of services are active or not.

Now that you’re aware of how the $chkconfig command works, you can proceed to learn about its syntax.

Syntax of the $chkconfig Command

The $chkconfig command has the following syntax:

$ chkconfig <options> <services> <subcommands>

While the $chkconfig command can be used on its own, it requires options and flags to maximize its functionality. A list of commonly used options is given below:

  • --override <service name>: Switches the settings for a given service from the default configuration to override.
  • <service name> reset: Used to reset the status(on/off) of the given services.
  • <service name> resetpriorities: Used to reset the priorities(start/stop) of the given services.
  • --del <service name>: Used to delete the given service from the run levels at startup.
  • --add <service name>: Used to add the given service to all the run levels at startup.
  • --level <run levels> <service> off: Used to turn off a specific service within a single or multiple run levels.
  • --level <run levels> <service> on: Used to turn on a specific service within single or multiple run levels.
  • <service> on: Used to enable the given service at system startup.
  • <service> off: Used to disable the given service at system startup.
  • --list: Used to display all available services and their startup statuses for every run level.
  • --list | sort: Used to display all available services alphabetically and their startup statuses for every run level.
  • --list | grep off: Used to display all disabled services and their startup statuses for every run level.
  • --list | grep on: Used to display all enabled services and their startup statuses for every run level.
  • --list | grep --level <levels>: off: Used to display all disabled services and their startup statuses for specific run levels.
  • --list | grep --level <levels>: on: Used to display all enabled services and their startup statuses for specific run levels.

Now that you’re aware of the syntax for the $chkconfig command, let’s take a look at some of these options in action.

Example 1: Displaying All Available Services

This example will cover how you can view all services that are available at startup for all run levels.

Follow these steps to display the available services:

  1. Start by opening the Command Terminal.
  2. Next, type the following to list all available services during your system’s startup:
$ chkconfig --list

The output should consist of service names followed by run levels and their active statuses.

Example 2: Displaying Specific Services

Aside from listing all services, you can also use $chkconfig to specify a service. This can be done using the $ | grep <service> option.

To display a specific service using $chkconfig, open the Command Terminal and type the following:

$ chkconfig --list | grep <service name>

In our case, 

$ chkconfig --list | grep sshd

Additionally, you can also specify services by their status on a specific run level. To do so, you’ll need to type the following in the Command Terminal:

$ chkconfig --list | grep <run level>:<status (on/off)>

For example,

$ chkconfig --list | grep 4:off

Example 3: Enabling a Specific Service for Run Levels

If you want to turn a specific service on at a single run level, you can use the $level option.

Warning: When using $chkmod with anything but $ --list, ensure that you have $sudo or $root privileges available for your account.

Follow these steps to enable the services for specified run levels.

  1. Begin by opening the Command Terminal by pressing “Ctrl + Alt +T” on your keyboard.
  2. Once the Terminal is open, type the following command to gain root access:
$ sudo -i
How to Use the chkconfig Command on Linux
  1. Type your password and press the “Enter” key to enable root mode.
  2. Lastly, to enable a specific service, type the following in the Terminal:
$ chkconfig --level <run level number (1-6)> <service> on

For Example,

$ chkconfig --level 3 httpd on

In case you wish to enable a service for multiple levels, you can do so by mentioning the level number without the space. For example.

$ chkconfig --level 45 sshd on

This will enable the sshd service on run levels 4 and 5.

Example 3: Disabling a Specific Service for Run Levels

If you wish to turn a specific service off at a single run level, you can use the $level option.

Warning: When using $chkmod with anything but the $ --list, make sure that you have $sudo or $root privileges available for your account.

Follow these steps to disable a particular service on a run level.

  1. Start by opening the Command Terminal.
  2. Once that’s done, enable root by typing the following:
$ sudo -i
How to Use the chkconfig Command on Linux
  1. With root enabled, type the following command to disable a specific service
$ chkconfig --level <run level number (1-6)> <service> off

For Example,

$ chkconfig --level 3 httpd off

While working with $chkconfig, you may have noticed that writing it repeatedly can prove to be a hassle. Fortunately, Linux allows you to create aliases for such commands. Learning how to create aliases can save you from the trouble of writing long commands again and again.

This concludes our guide on how to use the chkconfig command on Linux. If you have any questions, comments, or suggestions, let us know in the comments.

If this guide helped you, please share it.

Leave a Reply
Related Posts