Ad Widget

Collapse

Remotely Execute Script as another user

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nethaumea
    Junior Member
    • Dec 2022
    • 1

    #1

    Remotely Execute Script as another user

    I have the following script on a RHEL host: /home/user1/myscript.sh

    I have a trigger action set as 'Remote Command' with the command set to "/home/user1/myscript.sh".

    When I go to Monitoring -> Hosts -> myhost -> scripts -> myscript, It says "Permission denied". I'm assuming because it's trying to run this as the zabbix agent user? How can I have it execute as user1?
  • Markku
    Senior Member
    Zabbix Certified SpecialistZabbix Certified ProfessionalZabbix Certified Expert
    • Sep 2018
    • 1782

    #2
    sudo -u user1 /home/user1/myscript.sh

    You will need to configure /etc/sudoers.d/zabbix with such a line that allows zabbix user to change to user1 and run the command.

    Also note that the script has to have the relevant execute bits set with chmod, if that's your problem.

    Markku

    Comment

    • lbm
      Member
      • Feb 2020
      • 36

      #3
      Move it to /usr/local/ or something where the user have access, and assign zabbix user correct permissions to the file as well.

      Comment

      • themactech
        Junior Member
        • Dec 2022
        • 7

        #4
        I think the easy solution is (as mentioned above) setting the proper privileges so both the zabbix user and your 'user1' can both execute it, unless for some reason or another you cannot have it run for any other user than 'user1'.

        Comment

        • Yafimm
          Junior Member
          • May 2022
          • 9

          #5
          It looks like the issue you are experiencing is due to the fact that the Zabbix agent does not have permission to execute the script as user1.

          To have the script execute as user1, you will need to give the Zabbix agent permission to do so. One way you can do this is by adding the Zabbix agent user to the user1 group, and then granting the user1 group execute permission on the script:
          1. Add the Zabbix agent user to the user1 group:
          sudo usermod -a -G user1 zabbix
          1. Grant the user1 group execute permission on the script:
          sudo chmod g+x /home/user1/myscript.sh
          This will allow the Zabbix agent to execute the script as user1.

          Alternatively, you can also modify the script to run as user1 using the "sudo" command. For example, you could modify the trigger action command to "/usr/bin/sudo -u user1 /home/user1/myscript.sh". This will run the script as user1 using the sudo command, which will require the Zabbix agent to have the appropriate permissions in the sudoers file.

          I hope this helps! Let me know if you have any questions.

          Comment

          Working...