4

I can run the following command from my shell without issue

sudo -u ktrl /home/andrew/.cargo/bin/ktrl -d /dev/input/event3

However, when I try to make a service:

/etc/systemd/system/ktrl.service

[Unit]
Description=ktrl

[Service]
User=ktrl
Environment=HOME=/opt/ktrl
ExecStart=/home/andrew/.cargo/bin/ktrl -d /dev/input/event3
  
[Install]
WantedBy=multi-user.target

I get the following error from systemctl status ktrl.service

     Loaded: loaded (/etc/systemd/system/ktrl.service; enabled; vendor preset: disabled)
     Active: failed (Result: exit-code) since Sat 2020-06-27 10:35:08 EDT; 5s ago
    Process: 23335 ExecStart=/home/andrew/.cargo/bin/ktrl -d /dev/input/event3 (code=exited, status=203/EXEC)
   Main PID: 23335 (code=exited, status=203/EXEC)
        CPU: 5ms

Jun 27 10:35:08 localhost.localdomain systemd[1]: Started ktrl.
Jun 27 10:35:08 localhost.localdomain systemd[23335]: ktrl.service: Failed to execute command: Permission denied
Jun 27 10:35:08 localhost.localdomain systemd[23335]: ktrl.service: Failed at step EXEC spawning /home/andrew/.cargo/bin/ktrl: Permission denied
Jun 27 10:35:08 localhost.localdomain systemd[1]: ktrl.service: Main process exited, code=exited, status=203/EXEC
Jun 27 10:35:08 localhost.localdomain systemd[1]: ktrl.service: Failed with result 'exit-code'.

I'm executing the command sudo -u ktrl /home/andrew/.cargo/bin/ktrl -d /dev/input/event3 as andrew. However, even if I switch to ktrl sudo su ktrl and run the command /home/andrew/.cargo/bin/ktrl -d /dev/input/event3 it still works

Results of running ll -d:

in /home/andrew

drwxr-xr-x. 39 andrew andrew 4.0K Jun 27 12:06 .

in /home/andrew/.cargo

drwxrwxr-x. 4 andrew andrew 4.0K Jun 25 16:11 .

in /home/andrew/.cargo/bin

drwxrwxr-x. 2 andrew andrew 4.0K Jun 25 16:11 .

Result of running ls -l in /home/andrew/.cargo/bin

total 1552
-rwxrwxrwx. 1 andrew andrew 1579608 Jun 25 16:11 ktrl
3
  • Are you executing it manually as the user andrew? – Nasir Riley Jun 27 '20 at 14:48
  • I'm executing the command sudo -u ktrl /home/andrew/.cargo/bin/ktrl -d /dev/input/event3 as andrew. However, even if I switch to ktrl sudo su ktrl and run the command /home/andrew/.cargo/bin/ktrl -d /dev/input/event3 it still works – user1991252 Jun 27 '20 at 14:50
  • Run ll -d on /home/andrew and add the output to your question. – Nasir Riley Jun 27 '20 at 15:29
3

The issue was caused by SELinux. I disabled it and now everything is working.

Edit: A better solution is to move the bin to /usr/local/bin/ktrl and to update the ktrl.service file accordingly. This way it will still work with SELinux enabled.

4
  • 2
    There's surely a better compromise solution than disabling SELinux altogether. – Jeff Schaller Jun 27 '20 at 16:19
  • @JeffSchaller SeLinux has never been user-friendly and unfortunately remains so. – Artem S. Tashkinov Jun 27 '20 at 16:29
  • There are also better ways than having software executed from a home directory and giving 777 permissions to its binary. – Nasir Riley Jun 27 '20 at 16:45
  • 1
    @ArtemS.Tashkinov Security has never been user-friendly. And to some serious degree that will always be the case. – Hauke Laging Jun 27 '20 at 18:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.