rc.local is a shell script executed once at the end of the boot process that lets an administrator run arbitrary commands without writing a full service definition. In Linux system initialization, it originated in the BSD and SysVinit tradition as the last script called after all runlevel scripts finished, and it survives today mainly as a compatibility mechanism under systemd.
The file usually lives at /etc/rc.local or, on older Red Hat systems, at /etc/rc.d/rc.local. It is simple to use, which explains its long popularity, but it offers no dependency handling, no restart logic and limited logging, so modern practice treats it as a last resort rather than a default tool.
How rc.local runs during boot
rc.local runs as root, once per boot, after the main services have started. Under SysVinit, the init process walked through the scripts of the target runlevel in /etc/rc2.d or a similar directory and then called rc.local as the final step before login prompts appeared. Because it ran last, administrators could assume that networking and file systems were already available.
Under systemd, the script is handled by a generator and a compatibility unit called rc-local.service. The generator systemd-rc-local-generator checks whether /etc/rc.local exists and is executable; only then does it pull the unit into the boot transaction. The unit is ordered after network.target, which does not guarantee that the network is fully configured, a detail that causes many startup failures.
The following table summarizes how the main init systems treat the script.
| Init system | How rc.local is invoked | Typical location |
|---|---|---|
| SysVinit | Called by the last runlevel script | /etc/rc.d/rc.local or /etc/rc.local |
| systemd | rc-local.service via a generator | /etc/rc.local, must be executable |
| OpenRC | Replaced by local.d scripts | /etc/local.d/*.start |
| Upstart | rc-sysinit job ran the legacy chain | /etc/rc.local |
| BSD init | Called from /etc/rc after base services | /etc/rc.local |
Structure and requirements of the script
A working rc.local needs a valid interpreter line, execute permission and a zero exit status. The first line is normally #!/bin/sh -e, where the -e option makes the shell stop at the first failing command. The script traditionally ends with exit 0, because a non-zero exit marks the systemd unit as failed.
Many current distributions, including Debian and Ubuntu, no longer ship the file at all, so an administrator must create it and set permissions with chmod +x /etc/rc.local. The table below lists the conditions that decide whether the script actually runs.
| Requirement | Why it matters | Symptom if missing |
|---|---|---|
| Shebang line | Defines the interpreter | Exec format error in the journal |
| Execute permission | The generator ignores non-executable files | Unit never starts, no error shown |
| Exit status 0 | systemd records success | rc-local.service shown as failed |
| Absolute paths | PATH is minimal at boot | Command not found |
| Background long jobs | Avoids blocking the unit timeout | Boot delay or killed process |
Long-running programs started from rc.local should be sent to the background with an ampersand or, better, moved into a proper service. Otherwise the unit waits for them and systemd may terminate the process when the start timeout expires, which by default is about 90 seconds.
rc.local compared with modern alternatives
The modern replacement for rc.local is a dedicated systemd unit, usually a Type=oneshot service with explicit ordering. Such a unit declares what it needs, for example After=network-online.target together with Wants=network-online.target, and its output goes to the journal where journalctl -u can show it.
Other mechanisms cover narrower needs. A cron @reboot entry runs a command per user after the cron daemon starts, a systemd timer can delay execution, and udev rules react to devices appearing. The comparison helps pick the right tool.
| Mechanism | Strengths | Weaknesses |
|---|---|---|
| rc.local | Trivial to write, familiar | No dependencies, weak logging |
| systemd oneshot unit | Ordering, logging, sandboxing | Requires unit file syntax |
| cron @reboot | Works for unprivileged users | Runs early, no ordering control |
| systemd timer | Delayed or repeated runs | Two files to maintain |
| udev rule | Triggered by hardware events | Not for long-running tasks |
When rc.local is still a reasonable choice
rc.local remains acceptable for small, idempotent, quick commands on systems an administrator fully controls. Typical examples are writing a value into /sys, loading a kernel tunable that has no sysctl equivalent, or setting a CPU frequency governor on a test machine.
It is a poor choice for anything that must be reliable, observable or portable. The decision table below reflects common operational practice.
| Situation | Recommended method | Reason |
|---|---|---|
| One-line tweak on a lab host | rc.local | Fast and good enough |
| Daemon that must restart on failure | systemd service | Restart policies built in |
| Task needing a configured network | Unit with network-online.target | Explicit dependency |
| Kernel parameter at boot | sysctl.d or kernel command line | Native and documented |
| Fleet managed by configuration tools | Packaged unit file | Reproducible deployment |
Common mistakes and failure modes
Most rc.local problems come from assumptions about boot timing and environment. Because the script inherits a minimal environment, commands that work in an interactive shell often fail silently at boot.
- Missing execute bit: on systemd the script is simply ignored, and nothing obvious reports it.
- Network not ready:
network.targetonly means networking setup has started, so mounts or downloads fail intermittently. - Blocking commands: a foreground loop delays the unit and can be killed at the timeout.
- Assuming user environment: variables from login profiles are absent, so relative paths break.
- No logging: output is lost unless redirected, so add
loggercalls or checkjournalctl -u rc-local.
A further risk is security: because the script runs as root, any writable file it calls becomes a privilege escalation path. Permissions on rc.local and everything it invokes should be restricted to root.
A non-technical view
Think of rc.local as a sticky note left for the computer that says: once you have finished starting up, please also do these few things. The computer reads the note every time it boots and follows the instructions in order.
The note is easy to write, which is why people liked it. But it cannot say what to do if something goes wrong, and it does not keep a good record of what happened. Modern Linux systems prefer proper service descriptions, which are like detailed work orders instead of sticky notes.
A concrete example
A system administrator runs a small Ubuntu server used as a home lab router. After each reboot, the server needs IP forwarding enabled on one interface and a disk set to spin down after 20 minutes of inactivity. Writing two systemd units for this feels excessive, so the administrator creates /etc/rc.local with a shebang, the two commands using absolute paths and a final exit 0, then runs chmod +x.
On the next boot, systemctl status rc-local shows the unit as active and exited, and the settings are in place. Later, when the administrator adds a command that mounts a network share, it fails on some boots because the network is not yet configured. The fix is to move that mount into a dedicated unit ordered after network-online.target, while the two simple tweaks stay in rc.local.