Having certain services start automatically can be useful in Kali Linux. For example, let's say I want to be able to SSH (covered in the Configuring and using SSH recipe) to my Kali Linux distribution. By default, the SSH server does not start in Kali, so I would need to log in to the virtual machine, open a Terminal, and run the command to start the service.
Managing Kali services
Getting ready
Prior to modifying the Kali Linux configuration, you will need to have installed the operating system on a virtual machine. If you have not already done this, refer to the Installing Kali Linux recipe.
How to do it...
Working with Kali Linux:
- We begin by logging in to our Kali Linux distribution and opening a Terminal window. Type in the following command:
- More than likely, it is already installed, and you will see a message like this:
- So now that we know it is installed, let us see whether the service is running. From the Terminal, type this:
- If the SSH server is not running, you will see something like this:
- Type Ctrl + C to get back to the prompt. Now let's start the service and check the status again by typing the following command:
- You should now see something like the following:
- So now, the service is running. Great, but if we reboot, we will see that the service does not start automatically. To get the service to start every time we boot, we need to make a few configuration changes. Kali Linux puts in extra measures to make sure you do not have services starting automatically. Specifically, it has a service whitelist and blacklist file. So to get SSH to start at boot, we will need to remove the SSH service from the blacklist. To do this, open a Terminal window and type the following command:
- Navigate down to the section labeled List of blacklisted init scripts and find ssh. Now, we will just add a # symbol to the beginning of that line, save the file, and exit. The file should look similar to the following screenshot:
- Now that we have removed the blacklist policy, all we need to do is enable SSH at boot. To do this, run the following commands from your Terminal:
That's it! Now when you reboot, the service will begin automatically. You can use this same procedure to start other services automatically at boot time.
How it works...
The rc.local file is executed after all the normal Linux services have started. It can be used to start services you want available after you boot your machine.