- Unix Commands Reference
- Unix Commands - Home
chkconfig Command in Linux
chkconfig stands for "change configuration". Specifically, it modifies the runlevel settings for system services. The chkconfig command is a tool used in Linux to manage how services are started or stopped at different runlevels.
Runlevels are numbered system states that define which services should be running on a system during boot or at specific points in time.
Table of Contents
Here is a comprehensive guide to the options available with the chkconfig command −
- Understanding chkconfig Command in Linux
- Install chkconfig Command in Linux
- How to use chkconfig Command in Linux?
- Examples of chkconfig Command in Linux
- Alternatives of chkconfig Command in Linux
Understanding chkconfig Command in Linux
The chkconfig works with runlevels, which are different operating system states. By default, commands like chkconfig <service> on set the service to start at runlevels 2, 3, 4, and 5 (multi-user modes).
Runlevels are numbered system states that define which services should be running on a Linux system.
Common runlevels include −
- 0 − Halt (system shutdown)
- 1 − Single-user mode (basic functionality for system maintenance)
- 2 − Multi-user mode without a graphical interface (text-based login)
- 3 − Multi-user mode with graphical interface (default for desktops)
- 4 − Not used by default, but can be configured for specific purposes
- 5 − X11 windowing system (graphical interface)
- 6 − Reboot (system restart)
Install chkconfig Command in Linux
Installing chkconfig might not provide any benefit and could potentially cause conflicts with systemd. However, on modern Linux distributions that utilize systemd as the init system, chkconfig might not be actively maintained or installed by default.
Here's how to approach the installation of chkconfig −
Check if chkconfig is already installed by opening a terminal window and typing −
which chkconfig
If chkconfig is installed, the terminal will display the path to the command. If not, it will display a message like “nothing” or "command not found."
Installation of chkconfig (if not pre-installed)
The installation method depends on your Linux distribution's package manager. Here are some common examples
For Debian/Ubuntu −
sudo apt-get install initscripts # Might install chkconfig along with other init system-related tools
For Red Hat/CentOS/Fedora −
sudo yum install initscripts # Similar to Debian/Ubuntu
For Arch Linux −
sudo pacman -S sysvinit # Installs System V init scripts, potentially including chkconfig
How to use chkconfig Command in Linux?
The chkconfig command is a fundamental tool in Linux for managing how services are started or stopped at different runlevels. It allows you to control which services are automatically launched during system boot and which ones remain inactive.
chkconfig [options] service_name
- options − Flags that modify chkconfig behavior (explained later)
- service_name − The name of the service to configure.
Here's a breakdown of the different options available with chkconfig. The options available with chkconfig are −
Options | Descriptions |
---|---|
--list or -l | Lists all available services and their current runlevel settings. This is the most common option used to get an overview of how services are configured. |
--add or -a service_name | Adds a service to the system's service configuration for the default runlevel. The service will be included in the startup process at the specified runlevel. |
--del or -d service_name | Removes a service from the system's service configuration for the default runlevel. The service will no longer be started or stopped at runlevels unless explicitly enabled. |
--level level_number service_name | Modifies the runlevel settings for a specific service. Here, level_number represents a valid runlevel (usually 0-6) and service_name is the name of the service to configure. |
Valid sub-options | |
on | Starts the service at the specified runlevel. |
off | Disables the service at the specified runlevel. |
reset | Resets the runlevel settings for the service to the default (usually based on system configuration files). |
Special Options | |
--force or -f | Forces chkconfig to update service configuration files even if they are read-only. Use this with caution, as it could potentially cause issues if the files are not supposed to be modified. |
--quiet or -q | Suppresses most output messages, only showing errors or warnings. |
Note − By understanding these options, you can effectively control how the chkconfig command behaves and tailor it to your specific needs when managing group ownership of files and directories in Linux.
Examples of chkconfig Command in Linux
Let's delve into some practical examples of how the chkconfig command can be utilized −
Example 1: List All Services and Their Runlevel Settings
This is the most commonly used option. It displays a list of all available services on your system and their current runlevel settings. Each service will be displayed with a code indicating its startup behavior at different runlevels (usually 0-6).
sudo chkconfig --list # or chkconfig -l
The codes displayed typically look like X:Y: Z, where X, Y, and Z represent the runlevels (e.g., 3:on: off). This indicates that the service is enabled (on) at runlevel 3 and disabled (off) at runlevels 1 and 2.
Example 2: Enable a Service at runlevel 3 (Default Desktop)
This command enables the httpd (Apache web server) service to start automatically at run level 3 (usually the default desktop mode). The --level option (or -l with the runlevel number) specifies the runlevel to modify and instructs chkconfig to enable the service at that level.
sudo chkconfig --level 3 httpd on # or chkconfig -l 3 httpd on
Note − This enables the httpd (Apache web server) service to start automatically at runlevel 3.
Example 3: Disable a Service at All Runlevels
This command removes the sshd (secure shell) service from the service configuration for all runlevels. This effectively disables the service at all startup states. Use caution as disabling critical services could affect system functionality.
sudo chkconfig --del sshd # or chkconfig -d sshd
This removes the sshd (secure shell) service from the service configuration for all runlevels, effectively disabling it.
Example 4: Reset the Runlevel Settings for a Service
This command resets the runlevel settings for the httpd service at runlevel 3. The service behavior will be determined by system configuration files or other mechanisms.
sudo chkconfig --level 3 httpd reset # or chkconfig -l 3 httpd reset
Example 5: Enable a Service at Default Runlevels (Usually 2, 3, 4, 5)
This command adds the postfix (mail server) service to the system's service configuration for the default runlevels. The specific default runlevels might vary depending on your system configuration but often include multi-user modes (2, 3, 4) and the graphical interface (5).
sudo chkconfig --add postfix # or chkconfig -a postfix
Note − Remember that sudo privileges are typically required as chkconfig modifies system configuration files.
Alternatives of chkconfig Command in Linux
On modern systems that utilize systemd, chkconfig is often deprecated in favor of the more robust and versatile systemctl command.
Here's a breakdown of the alternatives −
- systemctl (systemd Systems) − The recommended tool for managing services in systemd-based systems. It offers a wider range of functionality compared to chkconfig.
- System Management Tools − Some distributions provide GUI tools for managing services, which might be easier for beginners. If you're unsure whether to use chkconfig or systemctl, it's generally safer to use systemctl as it's the standard approach for modern Linux distributions.
- Service Configuration Files (Advanced) − For advanced users, systemd service configuration files (*.service) can be directly edited to manage service startup behavior.
Conclusion
While chkconfig is a classic tool for service management in Linux, it's primarily used with older init systems like System V init. Use chkconfig cautiously, especially when modifying system-critical services, as incorrect configurations could lead to unexpected behavior or system instability.
While still present on some systems, chkconfig is considered less common on modern Linux distributions that utilize systemd as the init system. For systemd systems, systemctl is the preferred approach for service management.