I want to run a command that requires sudo
, but non-interactively, so typing in a password isn't an option. In my specific case I want to create an automator/shortcut action on my phone to execute this script on my server via an ssh login.
In my case, I want to start a virtual machine with virsh start
, which I know I can configure to allow a non-root user to start the machine, but I'm curious about this solution in general, especially in a case where a non-root option isn't available.
I'm also picturing that the unprivileged user only needs to be able to run a single script that I define, not an arbitrary command. In other words, the user simply needs to be able to trigger the script to run - they do not supply any arguments, and even if they found a way to do so the arguments would be ignored.
Also in my case the server is only used by me, and is behind a firewall. It has internet connectivity (In that it can download things), but cannot be accessed from the internet. I either have to be on my LAN or connected via VPN to reach it, and I only expect to use this script while specifically at home. Still - I'm concerned about learning "good practice" here.
The server itself is running Debian Testing. My concern is allowing passwordless sudo seems risky. Is there a better way to do this where a theoretically unprivileged account can trigger a privileged script or command to run? Should I just use a script running as root
to monitor for some file to be created every minute or so and have the script just touch
that file? Can I create a user who can only sudo
that script?