1

I want to be able to allow users to run a specific command as another user, is this possible?

I have a script that reads a remote file through ssh to get a status, something like:

#!/usr/bin/sh

state=$(ssh -q -i $HOME/.ssh/id_rsa" auto@remote-host "[ -f /path/to/state/file ] && cat /path/to/state/file 2>/dev/null")

printf "${state}"

The auto user has a key setup so that it can login to the remote machine without a password. I want users to be able to run this script without needing to worry about setting up their own key, for example:

bob@local-machine$ /path/to/state-check

So, the bob user can run the script as the auto user without hassle. I know you can use something like

su auto -c "/path/to/state-check"

But that would still require access to the auto user's password or sudo. Is there a way to set up a file that allows bob to run specific commands as auto passwordless? Or should I redesign the tool so that the state files are fetched and stored locally? I'm not really sure of a good way to do this. I'm running this on RHEL 9 machines.

Andrew
  • 11
  • 1

0 Answers0