0

I have recently started looking into Salt Stack and have installed a master Salt agent on an ubuntu VM.

To sun my commands when I am logged in I need to always use

sudo salt ....

Is there a way to enable the Salt to be ran with sudo by default? Meaning I don't need to type in the sudo password or use sudo at all.

I am new to linux so I apologise if this seems like a sily question. Thanks in advance

1 Answers1

2

You can create shell functions or wrapper scripts that run sudo for you. E.g. put a script like this in your $PATH (perhaps in $HOME/bin):

#!/bin/sh
sudo /path/to/tools/salt "$@"

You may want to put the actual binaries somewhere outside the user's PATH, so they don't get called directly by accident. Then just make the necessary sudo configurations to allow the user to run /path/to/real/salt instead.

If you like, you could make a more generic wrapper too, e.g.

#!/bin/sh
sudo "/path/to/tools/${0##*/}" "$@"

It takes the name of program to call from the name it was itself called as, so if called as pepper or /usr/local/bin/pepper it would run sudo pepper, and so on. Then you can symlink the various names to that same script.

To configure salt to run without a password, you can follow the instructions given here: How to run a specific program as root without a password prompt?.

ilkkachu
  • 133,243
  • 15
  • 236
  • 397
  • Would doing this mean I have to type in my sudo password at all? – user564693 Mar 09 '23 at 12:21
  • 1
    @user564693, that's controlled by the `sudo` config, look for the `NOPASSWD:` option there. – ilkkachu Mar 09 '23 at 12:23
  • 2
    @user564693 you can configure `sudo` to allow specific commands to be run with no password. So after you do what this answer describes, follow the instructions here: [How to run a specific program as root without a password prompt?](https://unix.stackexchange.com/a/13058) – terdon Mar 09 '23 at 12:30