Failed to enable unit: Access denied – while enabling a service on AWS REHL instance

kanudo asked:

When I run this command

sudo systemctl enable /home/ec2-user/my_custom.service

I get

Failed to enable unit: Access denied

And When I run

systemctl enable /home/ec2-user/my_custom.service

I get

==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-unit-files ====
Authentication is required to manage system service or unit files.
Authenticating as: Cloud User (ec2-user)
Failed to enable unit: Access denied

Now here I don’t have any password to setting the new using sudo passwd ec2-user and then using that password but still the same error

Here is content of my_custom.service




My answer:

Systemd units must be placed in one of the search paths that systemd looks for unit files in. They cannot be placed in any other directory.

Copy the file to /etc/systemd/system, run sudo systemctl daemon-reload and then you will be able to enable your service.

View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.