When customising background services, daemons, or server processes on modern Linux systems, system administrators frequently need to modify default parameters. Common operational tweaks include raising file descriptor limits (LimitNOFILE), modifying environment variables, adjusting process restart delays, or specifying alternate working directories.
A dangerous mistake made by novice administrators is directly opening and modifying the vendor-supplied unit file located in /lib/systemd/system/ or /usr/lib/systemd/system/. Whenever the package manager (such as APT or DNF) updates that software package, your manual edits will be silently overwritten by the new vendor file. Systemd provides an elegant, non-destructive architecture designed specifically to solve this problem: Drop-in Overrides created via the systemctl edit command. In this comprehensive guide, we examine how to use systemctl edit to write clean drop-in overrides, verify your changes, and maintain upgrade-safe Linux services.
Understanding Systemd Drop-in Overrides
Systemd reads service definitions in a strictly defined hierarchical order:
- Vendor Default Units (
/lib/systemd/system/): Installed and maintained directly by upstream package managers. Should never be modified manually. - Full Unit Overrides (
/etc/systemd/system/): Complete replacements that completely shadow the vendor file. Requires duplicating the entire original unit file. - Drop-in Snippets (
/etc/systemd/system/<service>.service.d/override.conf): Small, targeted configuration files that only define the exact directives you want to add or change. All untouched vendor settings continue to apply cleanly and receive upstream updates automatically.
The systemctl edit command automates the creation and validation of these drop-in directories, opening your preferred text editor and reloading the systemd daemon automatically upon saving.
How to Create a Drop-in Override with systemctl edit
To customise an existing service (for example, nginx.service or docker.service):
- Open your terminal and run the edit command with administrative privileges:
sudo systemctl edit nginx.service
Systemd automatically creates the directory /etc/systemd/system/nginx.service.d/ and opens a temporary buffer for an override.conf file in your default command-line text editor (such as nano or vim). The editor includes helpful commented instructions explaining where to place your directives.
Example 1: Setting Environment Variables in a Service
To pass custom environment variables to a daemon without altering its system binary, add the section header and directive between the comment lines:
[Service]
Environment="NODE_ENV=production"
Environment="PORT=8080"
Save and exit the text editor (in nano, press Ctrl + O, then Enter, followed by Ctrl + X). Systemd will validate the syntax and automatically execute systemctl daemon-reload.
Example 2: Overriding ExecStart (Clearing the Original Command)
Directives that define executable commands (like ExecStart= or ExecStop=) in systemd accumulate unless explicitly reset. If you want to change the launch arguments of a service, you must first supply an empty ExecStart= line to clear the default vendor command, followed immediately by your new command:
[Service]
ExecStart=
ExecStart=/usr/sbin/nginx -g 'daemon on; master_process off;'
If you omit the blank ExecStart= line, systemd will attempt to execute both commands simultaneously and report a configuration error.
Example 3: Raising Resource Limits (LimitNOFILE)
High-traffic database and web servers often encounter the dreaded “Too many open files” socket error. You can permanently raise the file descriptor limit for a specific service using a drop-in override:
[Service]
LimitNOFILE=65536
Applying Changes and Verifying Overrides
After saving your drop-in file, restart the target service to apply the new configuration:
sudo systemctl restart nginx.service
To verify that systemd is recognising your drop-in override file, inspect the service status:
systemctl status nginx.service
In the status output, notice the line beginning with Drop-In:
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Drop-In: /etc/systemd/system/nginx.service.d
└─override.conf
Active: active (running) since Wed 2026-11-04 10:15:00 UTC; 1min ago
To view the fully resolved, merged configuration of all vendor units and drop-in snippets combined, run:
systemctl cat nginx.service
How to Remove a Drop-in Override
If you no longer need the customisation and want to revert the service entirely back to vendor defaults:
- Delete the override file:
sudo rm /etc/systemd/system/nginx.service.d/override.conf
- (Optional) Remove the empty drop-in directory:
sudo rmdir /etc/systemd/system/nginx.service.d/
- Reload the systemd daemon and restart the service:
sudo systemctl daemon-reload
sudo systemctl restart nginx.service
The service immediately returns to its clean upstream vendor configuration without leaving orphaned configuration fragments behind.