« Back to Systemd: Frequently Asked Questions

How to use systemctl edit to change a service?

How to use systemctl edit?

Run systemctl with the 'edit' subcommand and service.

systemctl edit UNIT.service

Introduction into changing systemd units

Systemd allows service units to be changed and customized. This is done using a drop-in file, which is often called override.conf. It overrides the vendor-supplied version of a service to customize it. Instead of duplicating the configuration, the override file contains the differences.

Editing a service file

Changing a service can be done using systemctl, followed by the edit subcommand and the service unit.

systemctl edit myservice.service

When using this command, it will open your default editor, such as vi. At this stage you can make any changes to the service file. Any changes should be placed between the comment section at the top and the comment section a little bit lower. Do not remove these comment sections, as systemctl uses these to see what changes you made.

Editing the primary unit

To edit the main configuration file, use the --full option. This is typically not a good idea for services that were installed using a package manager, but it is for your custom service units.

systemctl edit --full myservice.service

Overriding list entries

Some properties of a service may be repeated. These lists may for example define a path. It might be needed to first reset that property by defining it in your override file with an empty value. After that entry, add them in. If you also need the values from the original main configuration, add those as well.

Configuration check

After the edit action, ensure that the configuration has the right entries.

systemctl cat myservice.service

Activating changes

When making changes to units, a reload of systemd might be needed.

systemctl daemon-reload

Then reload the service.

systemctl restart myservice.service

Learn more about systemctl

This article uses the systemctl command to achieve its tasks. For this popular tool there is a cheat sheet available!

» Mastering the tool: systemctl

systemctl cheat sheet

Other questions related to Systemd

    Related articles

    Like to learn more? Here is a list of articles within the same category or having similar tags.

    Feedback

    Small picture of Michael Boelen

    This article has been written by our Linux security expert Michael Boelen. With focus on creating high-quality articles and relevant examples, he wants to improve the field of Linux security. No more web full of copy-pasted blog posts.

    Discovered outdated information or have a question? Share your thoughts. Thanks for your contribution!

    Mastodon icon