Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. Blockly
    5. [gelöst] Befehl als root ausführen oder Rechte ändern?

    NEWS

    • ioBroker@Smart Living Forum Solingen, 14.06. - Agenda added

    • ioBroker goes Matter ... Matter Adapter in Stable

    • Monatsrückblick - April 2025

    [gelöst] Befehl als root ausführen oder Rechte ändern?

    This topic has been deleted. Only users with topic management privileges can see it.
    • liv-in-sky
      liv-in-sky @waterchill last edited by

      @waterchill

      interessant - könntest du dein script nicht als service installieren auf linux ebene - dann kannst du mit systemctl restart ... usw arbeiten

      1 Reply Last reply Reply Quote 0
      • W
        waterchill @fastfoot last edited by

        @fastfoot

        Interessant, das Ergebnis ist wie folgt:

        pi@raspberrypi:~ $ cat /etc/sudoers.d/iobroker
        cat: /etc/sudoers.d/iobroker: Keine Berechtigung
        

        Ich habe folgendes Eingetragen:

        # User privilege specification
        root    ALL=(ALL:ALL) ALL
        iobroker        ALL= /etc/init.d/power_mqtt
        
        F 1 Reply Last reply Reply Quote 0
        • F
          fastfoot @waterchill last edited by

          @waterchill sagte in Befehl als root ausführen oder Rechte ändern?:

          @fastfoot

          Interessant, das Ergebnis ist wie folgt:

          pi@raspberrypi:~ $ cat /etc/sudoers.d/iobroker
          cat: /etc/sudoers.d/iobroker: Keine Berechtigung
          

          Ich habe folgendes Eingetragen:

          # User privilege specification
          root    ALL=(ALL:ALL) ALL
          iobroker        ALL= /etc/init.d/power_mqtt
          

          das sollte man so nicht machen, besser ist eine Datei anzulegen. probiere das cat mit sudo, es geht darum ob das file überhaupt schon existiert

          W 1 Reply Last reply Reply Quote 0
          • W
            waterchill @fastfoot last edited by

            @fastfoot

            pi@raspberrypi:~ $ sudo cat /etc/sudoers.d/iobroker
            iobroker ALL=(ALL) ALL
            iobroker ALL=(ALL) NOPASSWD: /sbin/shutdown
            iobroker ALL=(ALL) NOPASSWD: /sbin/halt
            iobroker ALL=(ALL) NOPASSWD: /sbin/poweroff
            iobroker ALL=(ALL) NOPASSWD: /sbin/reboot
            iobroker ALL=(ALL) NOPASSWD: /bin/systemctl start
            iobroker ALL=(ALL) NOPASSWD: /bin/systemctl stop
            iobroker ALL=(ALL) NOPASSWD: /bin/mount
            iobroker ALL=(ALL) NOPASSWD: /bin/umount
            iobroker ALL=(ALL) NOPASSWD: /usr/bin/systemd-run
            iobroker ALL=(ALL) NOPASSWD: /usr/bin/apt-get
            iobroker ALL=(ALL) NOPASSWD: /usr/bin/apt
            iobroker ALL=(ALL) NOPASSWD: /usr/bin/dpkg
            iobroker ALL=(ALL) NOPASSWD: /usr/bin/make
            iobroker ALL=(ALL) NOPASSWD: /bin/ping
            iobroker ALL=(ALL) NOPASSWD: /sbin/setcap
            iobroker ALL=(ALL) NOPASSWD: /usr/bin/vcgencmd
            iobroker ALL=(ALL) NOPASSWD: /bin/cat
            iobroker ALL=(ALL) NOPASSWD: /bin/df
            iobroker ALL=(ALL) NOPASSWD: /sbin/ldconfig
            ALL ALL=NOPASSWD: /bin/systemctl start iobroker
            ALL ALL=NOPASSWD: /bin/systemctl stop iobroker
            ALL ALL=NOPASSWD: /bin/systemctl restart iobroker
            ALL ALL=(iobroker) NOPASSWD: /usr/local/bin/node /opt/iobroker/node_modules/iobroker.js-controller/iobroker.js *
            
            F 1 Reply Last reply Reply Quote 0
            • F
              fastfoot @waterchill last edited by

              @waterchill sagte in Befehl als root ausführen oder Rechte ändern?:

              @fastfoot

              pi@raspberrypi:~ $ sudo cat /etc/sudoers.d/iobroker
              iobroker ALL=(ALL) ALL
              iobroker ALL=(ALL) NOPASSWD: /sbin/shutdown
              iobroker ALL=(ALL) NOPASSWD: /sbin/halt
              iobroker ALL=(ALL) NOPASSWD: /sbin/poweroff
              iobroker ALL=(ALL) NOPASSWD: /sbin/reboot
              iobroker ALL=(ALL) NOPASSWD: /bin/systemctl start
              iobroker ALL=(ALL) NOPASSWD: /bin/systemctl stop
              iobroker ALL=(ALL) NOPASSWD: /bin/mount
              iobroker ALL=(ALL) NOPASSWD: /bin/umount
              iobroker ALL=(ALL) NOPASSWD: /usr/bin/systemd-run
              iobroker ALL=(ALL) NOPASSWD: /usr/bin/apt-get
              iobroker ALL=(ALL) NOPASSWD: /usr/bin/apt
              iobroker ALL=(ALL) NOPASSWD: /usr/bin/dpkg
              iobroker ALL=(ALL) NOPASSWD: /usr/bin/make
              iobroker ALL=(ALL) NOPASSWD: /bin/ping
              iobroker ALL=(ALL) NOPASSWD: /sbin/setcap
              iobroker ALL=(ALL) NOPASSWD: /usr/bin/vcgencmd
              iobroker ALL=(ALL) NOPASSWD: /bin/cat
              iobroker ALL=(ALL) NOPASSWD: /bin/df
              iobroker ALL=(ALL) NOPASSWD: /sbin/ldconfig
              ALL ALL=NOPASSWD: /bin/systemctl start iobroker
              ALL ALL=NOPASSWD: /bin/systemctl stop iobroker
              ALL ALL=NOPASSWD: /bin/systemctl restart iobroker
              ALL ALL=(iobroker) NOPASSWD: /usr/local/bin/node /opt/iobroker/node_modules/iobroker.js-controller/iobroker.js *
              

              ok, sudo vi /etc/sudoers.d/iobroker

              dort in die 2te Zeile: iobroker ALL=(ALL) NOPASSWD: /etc/init.d/power_mqtt *

              vi beenden mit ESC-Taste, dann :wq!

              aus Blockly rufst du jetzt das script mit sudo /etc/init.d/power_mqtt auf

              die Änderungen in /etc/sudoers rückgängig machen!

              W F 2 Replies Last reply Reply Quote 0
              • OliverIO
                OliverIO @waterchill last edited by OliverIO

                @waterchill sagte in Befehl als root ausführen oder Rechte ändern?:

                Moin,

                ich kämpfe seit heute heute früh mit einem Problem. Ich möchte folgenden Befehl über blockly ausführen:

                /etc/init.d/power_mqtt restart

                Das Problem ist, der Befehl geht nur über sudo und sudo ist im Terminal nicht möglich. Habe folgendes versucht über ssh KOnsole des users pi:

                sudo chmod -v 777 power_mqtt

                -> kein Erfolg

                dann:

                sudo chown iobroker power_mqtt

                -> kein Erfolg

                dann:

                sudo visudo /etc/sudoers

                dort entsprechend eingetragen:

                iobroker ALL= /etc/init.d/power_mqtt

                -> kein Erfolg

                Nun bin ich mit meinem Wissen am Ende. Hat jemand einen Tipp?

                @waterchill

                Ich glaube bei den sudoers hast du noch einen fehler
                müsse es nicht so heissen:

                iobroker ALL=(ALL) NOPASSWD: /etc/init.d/power_mqtt
                

                ob es funktioniert, kannst du selbst auf der shell testen, in dem du dich als
                iobroker anmeldest mit

                sudo -u iobroker bash
                /etc/init.d/power_mqtt restart
                

                https://wiki.ubuntuusers.de/sudo/Konfiguration/

                W 1 Reply Last reply Reply Quote 0
                • W
                  waterchill @OliverIO last edited by

                  @oliverio

                  Habe es jetzt so rein, funktioniert leider auch nicht 😞

                  # User privilege specification
                  root    ALL=(ALL:ALL) ALL
                  iobroker ALL=(ALL) NOPASSWD: /etc/init.d/power_mqtt
                  
                  1 Reply Last reply Reply Quote 0
                  • W
                    waterchill @fastfoot last edited by waterchill

                    @fastfoot said in Befehl als root ausführen oder Rechte ändern?:

                    sudo vi /etc/sudoers.d/iobroker

                    Wenn ich das so ausführe, dann kann ich da drin nichts ändern, unten steht dann {readonly} ich komm dann auch nimmer raus aus dem Teil. Terminal muss dann beendet werden. Scheinbar wird die Datei gerade verwendet oder so

                    OliverIO 1 Reply Last reply Reply Quote 0
                    • F
                      fastfoot @fastfoot last edited by

                      @waterchill

                      @fastfoot sagte in Befehl als root ausführen oder Rechte ändern?:
                      vi beenden mit ESC-Taste, dann :wq!

                      W 1 Reply Last reply Reply Quote 0
                      • Dr. Bakterius
                        Dr. Bakterius Most Active @waterchill last edited by

                        @waterchill sagte in Befehl als root ausführen oder Rechte ändern?:

                        */2 16-20 * * * sudo /etc/init.d/power_mqtt restart
                        

                        Ja, aber statt sudo root.

                        W 1 Reply Last reply Reply Quote 0
                        • W
                          waterchill @Dr. Bakterius last edited by

                          @dr-bakterius

                          Ich habs mit sudo drin und scheint so zu gehen

                          1 Reply Last reply Reply Quote 0
                          • W
                            waterchill @fastfoot last edited by

                            @fastfoot

                            Also mit ESC komm ich da nich t raus. Ich kann da auch nichts reinschreiben.

                            F 1 Reply Last reply Reply Quote 0
                            • OliverIO
                              OliverIO @waterchill last edited by OliverIO

                              @waterchill
                              hm, du scheinst die befehle und konventionen nicht zu kennen.

                              Mit dem folgenden Befehl versuchst du diese Datei zu bearbeiten, da vi ein editor ist.

                              sudo vi /etc/sudoers.d/iobroker
                              

                              Wenn du die Dokumentation bei ubuntuusers liest, dann steht da sehr deutlich, dass man das Programm visudo
                              zur Bearbeitung nutzen soll, da man sich ansonsten hier ganz schnell das system zerschießen (also das ganze) kann, falls du einen syntaxfehler einbaust.

                              Zur Bearbeitung musst du also so aufrufen:

                              sudo visudo /etc/sudoers.d/iobroker
                              

                              Allerdings würde ich an dieser Datei nix verändern.
                              Wenn dann eine eigene Datei anlegen

                              sudo visudo /etc/sudoers.d/eigene
                              

                              Diese wird dann ebenso in die Abfrage mit eingebunden.

                              Aber bevor du irgendetwas machst, bitte die Seite
                              https://wiki.ubuntuusers.de/sudo/Konfiguration/von vorne bis hinten lesen.
                              Du arbeitest hier an den tiefsten eingeweide von Linux.

                              Wenn du sagstes funktioniert nicht. was heist das für dich? gibt es eine fehlermeldung.
                              woran merkst du dann ohne fehlermeldung, das es nicht funktioniert?
                              weißt du was der befehl eigentlich bedeutet?
                              /etc/init.d/power_mqtt restart

                              W 1 Reply Last reply Reply Quote 0
                              • F
                                fastfoot @waterchill last edited by

                                @waterchill sagte in Befehl als root ausführen oder Rechte ändern?:

                                @fastfoot

                                Also mit ESC komm ich da nich t raus. Ich kann da auch nichts reinschreiben.

                                du wirst doch lesen können! dahinter steht :wq!

                                mit dem ESC beendest du erstmal den Bearbeitungsmodus, mit : kommst du in die Befehlszeile und dann gibst du wq! ein. w=schreibe Änderungen, q= verlasse Editor, !=kümmere dich nicht um read-only.

                                Ich wundere mich, visudo funktioniert doch auch mit vi? Evtl kannst du auch vim nutzen, aber wenn installiert ruft vi den vim auf

                                1 Reply Last reply Reply Quote 0
                                • W
                                  waterchill @OliverIO last edited by

                                  @oliverio @fastfoot

                                  Erstmal ganz entspannt 😊 bevor ich solche Sachen probiere, lege ich immer ein Backup an. Das wäre ja fatal, wenn da nix mehr gehen würde in der Bude, da würde die Chefin mir die Hölle heiss machen^^

                                  Also ich habe die Zeile jetzt eingefügt bekommen, dementsprechend kommt jetzt raus:

                                  pi@raspberrypi:~ $ sudo cat /etc/sudoers.d/iobroker       
                                  iobroker ALL=(ALL) ALL
                                  iobroker ALL=(ALL) NOPASSWD: /etc/init.d/power_mqtt *
                                  iobroker ALL=(ALL) NOPASSWD: /sbin/shutdown
                                  iobroker ALL=(ALL) NOPASSWD: /sbin/halt
                                  iobroker ALL=(ALL) NOPASSWD: /sbin/poweroff
                                  iobroker ALL=(ALL) NOPASSWD: /sbin/reboot
                                  iobroker ALL=(ALL) NOPASSWD: /bin/systemctl start
                                  iobroker ALL=(ALL) NOPASSWD: /bin/systemctl stop
                                  iobroker ALL=(ALL) NOPASSWD: /bin/mount
                                  iobroker ALL=(ALL) NOPASSWD: /bin/umount
                                  iobroker ALL=(ALL) NOPASSWD: /usr/bin/systemd-run
                                  iobroker ALL=(ALL) NOPASSWD: /usr/bin/apt-get
                                  iobroker ALL=(ALL) NOPASSWD: /usr/bin/apt
                                  iobroker ALL=(ALL) NOPASSWD: /usr/bin/dpkg
                                  iobroker ALL=(ALL) NOPASSWD: /usr/bin/make
                                  iobroker ALL=(ALL) NOPASSWD: /bin/ping
                                  iobroker ALL=(ALL) NOPASSWD: /sbin/setcap
                                  iobroker ALL=(ALL) NOPASSWD: /usr/bin/vcgencmd
                                  iobroker ALL=(ALL) NOPASSWD: /bin/cat
                                  iobroker ALL=(ALL) NOPASSWD: /bin/df
                                  iobroker ALL=(ALL) NOPASSWD: /sbin/ldconfig
                                  ALL ALL=NOPASSWD: /bin/systemctl start iobroker
                                  ALL ALL=NOPASSWD: /bin/systemctl stop iobroker
                                  ALL ALL=NOPASSWD: /bin/systemctl restart iobroker
                                  ALL ALL=(iobroker) NOPASSWD: /usr/local/bin/node /opt/iobroker/node_modules/iobroker.js-controller/iobroker.js *
                                  

                                  Das war doch das Ziel oder? Trotzdem kann der Befehl aus der iobroker Konsole nicht ohne sudo ausgeführt werden. Meldung die gleiche wie immer. Zwischenzeitlich habe ich auch mal ein reboot gemacht, leider ohne Erfolg.

                                  F OliverIO 2 Replies Last reply Reply Quote 0
                                  • F
                                    fastfoot @waterchill last edited by

                                    @waterchill sagte in Befehl als root ausführen oder Rechte ändern?:

                                    Das war doch das Ziel oder? Trotzdem kann der Befehl aus der iobroker Konsole nicht ohne sudo ausgeführt werden. Meldung die gleiche wie immer. Zwischenzeitlich habe ich auch mal ein reboot gemacht, leider ohne Erfolg.

                                    die Zeile sorgt dafür, dass du sudo mit diesem Befehl anwenden darfst, was vorher ja nicht ging. Also sudo muss schon davor, aber das sollte jetzt aus Blockly oder der Konsole funktionieren

                                    1 Reply Last reply Reply Quote 0
                                    • OliverIO
                                      OliverIO @waterchill last edited by

                                      @waterchill

                                      ´nein sudo musst du dennoch angeben.
                                      nur sudo verlangt dann für diesen befehl kein passwort mehr

                                      W 1 Reply Last reply Reply Quote 0
                                      • W
                                        waterchill @OliverIO last edited by

                                        @oliverio @fastfoot

                                        DANKE geht!!! 🙂

                                        F 1 Reply Last reply Reply Quote 0
                                        • F
                                          fastfoot @waterchill last edited by

                                          @waterchill sagte in Befehl als root ausführen oder Rechte ändern?:

                                          @oliverio @fastfoot

                                          DANKE geht!!! 🙂

                                          vergiss nicht deine ursprüngliche Änderung in /etc/sudoers rückgängig zu machen!

                                          und im ersten Beitrag auf gelöst setzen, bitte

                                          W 1 Reply Last reply Reply Quote 0
                                          • W
                                            waterchill @fastfoot last edited by waterchill

                                            @fastfoot

                                            ist erledigt, Danke nochmal!

                                            Wenn wir jetzt schon so gut in Fahrt sind, gibt es eine Möglichkeit ein Skript zu erstellen, welches quasi pro 1 Puls mehr 1% mehr Lüftung macht? Aktuell hab eich 10er Schritte. Dem entsprechend natürlich 10 einzelne Bedingungen. Evtl gibt es da was wo es heisst: wenn das +1 dann das +1 und umgekehrt. Schaut aktuell so aus, evtl kann man das geschickter machen:

                                            Bildschirmfoto 2021-01-28 um 18.53.34 PM.png

                                            F 1 Reply Last reply Reply Quote 0
                                            • First post
                                              Last post

                                            Support us

                                            ioBroker
                                            Community Adapters
                                            Donate

                                            678
                                            Online

                                            31.7k
                                            Users

                                            79.8k
                                            Topics

                                            1.3m
                                            Posts

                                            7
                                            49
                                            3849
                                            Loading More Posts
                                            • Oldest to Newest
                                            • Newest to Oldest
                                            • Most Votes
                                            Reply
                                            • Reply as topic
                                            Log in to reply
                                            Community
                                            Impressum | Datenschutz-Bestimmungen | Nutzungsbedingungen
                                            The ioBroker Community 2014-2023
                                            logo