I would like to allow all users (or maybe only some of them but all would already be good) to be able to start/stop a specific systemd service.
I found the following solution
#include <stdlib.h>
#include <unistd.h>
int main(void)
{
execl("/usr/bin/systemctl", "systemctl", "start", "myService", NULL);
return(EXIT_SUCCESS);
}
gcc allow.c -o allow
chown root:root allow
chmod 4755 allow
That seems to do the trick but I am wondering if this is acceptable security-wise or if there are other options (I am using CentOS 7)
Update: this is bad practice. "sudo" is your best friend here since the command has specific non variable arguments it can be allowed in the sudoers file.