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

    Run command as a standard user instead of root?

    Scheduled Pinned Locked Moved General Discussion
    9 Posts 2 Posters 1.1k Views 1 Watching
    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.
    • ? Offline
      [[global:former-user]]
      last edited by

      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!

      RussR 1 Reply Last reply Reply Quote 0
      • RussR Offline
        Russ @Guest
        last edited by

        @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 Reply Quote 0
        • ? Offline
          [[global:former-user]] @Russ
          last edited by

          @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?

          RussR 1 Reply Last reply Reply Quote 0
          • RussR Offline
            Russ @Guest
            last edited by Russ

            @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
            • ? Offline
              [[global:former-user]]
              last edited by

              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!

              RussR 1 Reply Last reply Reply Quote 0
              • RussR Offline
                Russ @Guest
                last edited by

                @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 Reply Quote 0
                • ? Offline
                  [[global:former-user]] @Russ
                  last edited by

                  @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 Reply Quote 0
                  • ? Offline
                    [[global:former-user]] @Guest
                    last edited by

                    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!

                    RussR 1 Reply Last reply Reply Quote 0
                    • RussR Offline
                      Russ @Guest
                      last edited by

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

                      Russell VanderMey

                      1 Reply Last reply Reply Quote 0

                      Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                      Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                      With your input, this post could be even better 💗

                      Register Login
                      • First post
                        Last post