Profile.d script permission denied


I'm trying to disable ACPI wake on usb in Ubuntu 20.04
So I created a script in /etc/profile.d

-rwxr-xr-x 1 root root 110 May 18 00:23

#!/bin/sh -e
if cat /proc/acpi/wakeup | egrep 'XHC.*enabled'; then
    echo "XHC" > /proc/acpi/wakeup

When I start my machine it says permission denied. Why?

Best Answer

As mentioned in the comments, /etc/profile.d is being run as the user logging in, so will not have sufficient permissions to modify system configuration. You could add a sudo command there, but that would just mean you'll need to type your password again when you log in - this would be annoying and will also not work if the logging in user is not a system admin. Also, it will not do its job if no one is logging in after boot.

There are a few options, including adding /etc/rc.local as you mentioned, which was one of the common ways to do this kind of custom "on-boot" jobs before SystemD made the whole /etc/rc* thing irrelevant.

But - if you already have /etc/rc.local set up with your script, you can just enable it in SystemD by:

  1. Make sure /etc/rc.local is executable. For example by running chmod a+x /etc/rc.local. The SystemD compatibility mode will not work otherwise.
  2. Allow the SystemD compatibility mode to be enabled by creating the file /etc/systemd/system/rc-local.service.d/enable.conf with the contents below.
  3. Enable the SystemD compatibility by running sudo systemctl enable rc-local

/etc/systemd/system/rc-local.service.d/enable.conf :


Next time your system boot, SystemD will run your custom /etc/rc.local.

SystemD Alternatives

  1. Make use of SystemD tmpfiles management system to have it write what you need during boot. This is my recommended solution.
  2. See this AskUbuntu question for some people making SystemD services to do the same thing.
  3. I believe you can write a udev rule that disables "power/wakeup" when it sees whatever the XHC is (I think its the onboard XHCI USB hub?), as documented here: