Weblutions Documentation > Knowledgebase > How to enable /etc/rc.local on Ubuntu

How to enable /etc/rc.local on Ubuntu

rc.local is a legacy script on Unix-like systems (including Linux) that was traditionally used to run commands automatically. If you want to use it for running commands at startup, follow these updated steps to re-enable it using a custom SystemD service.

Step 1: Create the /etc/rc.local File

sudo touch /etc/rc.local
sudo chmod +x /etc/rc.local

Step 2: Add a Shebang and Exit Statement

Edit the file using your preferred text editor and include the following:

#!/bin/bash
# Add any startup commands below this line

exit 0

Any command placed above the exit 0 line will run at startup.

Step 3: Create a SystemD Service

Create a new SystemD service file:

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

Paste the following content:

[Unit]
Description=Compatibility for /etc/rc.local
ConditionPathExists=/etc/rc.local

[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
StandardOutput=tty
RemainAfterExit=yes
SysVStartPriority=99

[Install]
WantedBy=multi-user.target

Step 4: Reload SystemD and Enable the Service

sudo systemctl daemon-reload
sudo systemctl enable rc-local

Step 5: Start the Service

sudo systemctl start rc-local

Step 6: Confirm the Service is Running

sudo systemctl status rc-local

If successful, /etc/rc.local will now be executed on every system boot.


Related Articles


Suggest an edit

Review this page

faxes

2 recommend this page