Operations 3 min read

How to Add a Startup Script on Ubuntu Using the rc‑local Service

This guide explains how to create and enable an rc‑local startup script on Ubuntu by inspecting the rc‑local.service unit, creating /etc/rc.local, setting execution permissions, and enabling the service with systemctl so custom commands run automatically at boot.

Practical DevOps Architecture
Practical DevOps Architecture
Practical DevOps Architecture
How to Add a Startup Script on Ubuntu Using the rc‑local Service

On CentOS you can add startup commands to /etc/rc.local , but Ubuntu lacks this file, so you need to create a new startup file.

Run ls /lib/systemd/system to see existing service files, including rc-local.service . Example output:

root@gwzj:~# ll /lib/systemd/system/rc-local.service -rw-r--r-- 1 root root 785 Jan 8 17:46 /lib/systemd/system/rc-local.service

The typical rc-local.service file consists of three sections:

[Unit] : defines start order and dependencies.

[Service] : defines how the service runs and its type.

[Install] : defines how the unit is installed to start at boot (e.g., WantedBy=multi-user.target , Alias=rc-local.service ).

Step 2 – Create /etc/rc.local

Create the file with touch /etc/rc.local , add the shell commands you want to run (including the shebang line #!/bin/sh ), then make it executable with chmod +x /etc/rc.local . If you add a script like ./nginx.sh , append an ampersand ( & ) to avoid blocking the boot process.

Step 3 – Enable the rc‑local service

Enable the service so it starts on boot:

root@gwzj:~# systemctl enable rc-local.service

Step 4 – Verify

Reboot the server and confirm that the commands in /etc/rc.local execute as expected.

operationsLinuxstartupubuntusystemdrc-local
Practical DevOps Architecture
Written by

Practical DevOps Architecture

Hands‑on DevOps operations using Docker, K8s, Jenkins, and Ansible—empowering ops professionals to grow together through sharing, discussion, knowledge consolidation, and continuous improvement.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.