How to add rc.local in Debian

Submitted by Jeff on Sun, 23/10/2022 - 08:26

Source: Fonte

Since Debian 9, the traditional “rc.local” has been deprecated. For traditional Linux users and administrators, there is a way to get it back using SystemD. See the procedure below :

1. Edit the non-existing file “rc-local.service” :

nano /etc/systemd/system/rc-local.service

1.1. Add the following content to “/etc/systemd/system/rc-local.service” :


ExecStart=/etc/rc.local start


2. Edit the “rc.local” file :

nano /etc/rc.local

2.1. Append the generic content below and save the file :

#!/bin/sh -e
# rc.local
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
# In order to enable or disable this script just change the execution
# bits.
# By default this script does nothing.

exit 0

3. Change permissions :

chmod +x /etc/rc.local

4. Enable the “rc-local” script on boot :

systemctl enable rc-local

5. Start the “rc-local” script :

systemctl start rc-local.service

6. Check if any error occurred while starting the service :

systemctl status rc-local.service

You may now append anything you’d like to the traditional “rc.local” BEFORE exit 0.