• Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Register
  • Login
TRIGGERcmd
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Register
  • Login

Run command as a standard user instead of root?

General Discussion
2
9
494
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ?
    A Former User
    last edited by Dec 24, 2020, 6:14 PM

    Hi there,
    I have a command that I want to use under the 'pi' user instead of root.
    Am I able to run a command as the 'pi' user or install TCMD as 'Pi' instead?
    Thanks!

    R 1 Reply Last reply Dec 24, 2020, 6:34 PM Reply Quote 0
    • R
      Russ @A Former User
      last edited by Dec 24, 2020, 6:34 PM

      @Lewis-S, the simple way to run a command as the pi user would be to make a command like this:

      su - pi -c 'ls ~'
      

      That command will run ls ~ as the pi user, so it will list the files in the pi user's home directory.

      su is "switch user" command. Here's the man page for it: https://man7.org/linux/man-pages/man1/su.1.html

      Russell VanderMey

      ? 1 Reply Last reply Dec 24, 2020, 10:58 PM Reply Quote 0
      • ?
        A Former User @Russ
        last edited by Dec 24, 2020, 10:58 PM

        @Russ
        Hi Russ,
        That didn't work. I think systemctl is too big of an ask to run via su - pi.
        I might have to make it a system service, if it is not possible to run TCMD as non-root?

        R 1 Reply Last reply Dec 25, 2020, 3:05 PM Reply Quote 0
        • R
          Russ @A Former User
          last edited by Russ Dec 25, 2020, 3:06 PM Dec 25, 2020, 3:05 PM

          @Lewis-S, I just tested this on my Raspberry Pi and it worked for me. This is my commands.json entry.

           {
            "trigger": "pi user test",
            "command": "su - pi -c 'ls ~ > /tmp/ls.txt'",
            "offCommand": "",
            "ground": "background",
            "voice": "",
            "voiceReply": "",
            "allowParams": "false"
           },
          

          It is possible to run the agent as the pi user, but I figured this would be the easier method.

          If you still want to try running the agent as pi, you could start running this command while logged in as the pi user:

          triggercmdagent --console
          

          It will setup a new .TRIGGERcmdData folder in the pi user's home directory, so it will try to create another computer in your TRIGGERcmd account, so you'll either need to delete your existing computer from your account, or have a subscription.

          Russell VanderMey

          1 Reply Last reply Reply Quote 0
          • ?
            A Former User
            last edited by Dec 25, 2020, 10:53 PM

            Hi Russ,
            I did try that, but got the same error again. I think systemctl is a command too powerful to run via su.
            I'll look at other ways, like moving it to a system service or making it the root user's serivce.
            Thank you!

            R 1 Reply Last reply Dec 25, 2020, 11:19 PM Reply Quote 0
            • R
              Russ @A Former User
              last edited by Dec 25, 2020, 11:19 PM

              @Lewis-S, are you trying to run systemctl as the pi user via TRIGGERcmd? If not, what command are trying to run, and what error are you getting?

              If I know what you're trying to accomplish, I might be able to help.

              Russell VanderMey

              ? 1 Reply Last reply Dec 26, 2020, 9:59 AM Reply Quote 0
              • ?
                A Former User @Russ
                last edited by Dec 26, 2020, 9:59 AM

                @Russ Yes, that's what I want to do.
                I get " Failed to connect to bus: No such file or directory".

                ? 1 Reply Last reply Dec 26, 2020, 12:14 PM Reply Quote 0
                • ?
                  A Former User @A Former User
                  last edited by Dec 26, 2020, 12:14 PM

                  Hi @Russ
                  Update: I asked elsewhere and

                  su pi -c 'XDG_RUNTIME_DIR="/run/user/1000" systemctl --user status monitor.service'
                  

                  works, as it adds environment variables needed for systemctl to run.

                  Thanks!

                  R 1 Reply Last reply Dec 26, 2020, 2:55 PM Reply Quote 0
                  • R
                    Russ @A Former User
                    last edited by Dec 26, 2020, 2:55 PM

                    @Lewis-S, awesome. Nice job figuring that out.

                    Russell VanderMey

                    1 Reply Last reply Reply Quote 0
                    1 out of 9
                    • First post
                      1/9
                      Last post