# Execute systemctl commands from nodered on remote system?

**URL:** <https://discourse.nodered.org/t/execute-systemctl-commands-from-nodered-on-remote-system/100044>\
**Category:** General\
**Created:** [30 December 2025 06:13 UTC](https://discourse.nodered.org/t/execute-systemctl-commands-from-nodered-on-remote-system/100044 "2025-12-30T06:13:26Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jibun-no-Kage](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jibun-no-kage/32/99316_2.png) [@Jibun-no-Kage](https://discourse.nodered.org/u/Jibun-no-Kage)\
**Post date:** [30 December 2025 06:13 UTC](https://discourse.nodered.org/t/execute-systemctl-commands-from-nodered-on-remote-system/100044/1 "2025-12-30T06:13:26Z")

</div>

Execute systemctl commands from nodered on remote system? Since I am not running NR under root context, trying to find ways to do this. For example via exec node:

```auto
$ sudo systemctl --host=nodered@192.168.1.251 restart bind9.service

```

Have tried:

1. SSH keys from nodered to remote system - system demands interactive password

2. Tried adding nodered to suders configuration on all applicable systems - system still demands interactive password

Any other ideas? If I use NR under root suspect this would work... But would like to avoid it.

---

<div class="post-metadata">

**Author:** ![Jibun-no-Kage](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jibun-no-kage/32/99316_2.png) [@Jibun-no-Kage](https://discourse.nodered.org/u/Jibun-no-Kage)\
**Post date:** [30 December 2025 06:31 UTC](https://discourse.nodered.org/t/execute-systemctl-commands-from-nodered-on-remote-system/100044/2 "2025-12-30T06:31:35Z")

</div>

So apparently the following variant works... via an exec node:

```auto
ssh nodered@192.168.1.251 'sudo systemctl restart bind9.service'

```

Of course you have to get the 'nodered' id explicit permission via sudo to execute the above command.

```auto
# visudo /etc/sudoers.d/010_nodered
// Add...
nodered ALL=(ALL) NOPASSWD: /usr/bin/systemctl restart bind9.service

```

And of course you have to setup SSH key to allow ssh shell password avoidance not just sudoer password avoidance.

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [30 December 2025 09:32 UTC](https://discourse.nodered.org/t/execute-systemctl-commands-from-nodered-on-remote-system/100044/3 "2025-12-30T09:32:15Z")

</div>

There are 2 possible things that could cause this as far as I can see.

The most probable is that it is sudo asking for the password. You are directly triggering sudo on the node-red server so you need to ensure that the command you are triggering is the one you have put into sudoers. However, I'm not sure if you also trigger sudo on the remote system as well? If so, perhaps you need to add the command into that sudoers config as well?

The less likely reason would be that the host request is trying to ask for the password for the `nodered` user on the remote?

Are you actually running Node-RED on the remote server? If so, it would be easier possibly to have a flow on that server itself that restarts bind9 and then trigger that flow either via a webhook or an MQTT message.

---

<div class="post-metadata">

**Author:** ![Jibun-no-Kage](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jibun-no-kage/32/99316_2.png) [@Jibun-no-Kage](https://discourse.nodered.org/u/Jibun-no-Kage)\
**Post date:** [31 December 2025 01:41 UTC](https://discourse.nodered.org/t/execute-systemctl-commands-from-nodered-on-remote-system/100044/4 "2025-12-31T01:41:43Z")

</div>

And my workaround seems to work... but does not work. I get no error, I get all the response prompts/text I expect to see... but the result is a type of 'no-op' in that the command appears to run, execute, but systemd still shows the service as dead, offline. Result code is 0, which denotes correct execution... well.

If I run the exact command locally works. If I run the exact command on a remote server, it works. It is only when I run it via NR it appears to work but does not... interesting. Somewhere some way, I think I missed something.

---

<div class="post-metadata">

**Author:** ![Jibun-no-Kage](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jibun-no-kage/32/99316_2.png) [@Jibun-no-Kage](https://discourse.nodered.org/u/Jibun-no-Kage)\
**Post date:** [31 December 2025 01:43 UTC](https://discourse.nodered.org/t/execute-systemctl-commands-from-nodered-on-remote-system/100044/5 "2025-12-31T01:43:18Z")

</div>

As for using MQTT... I could also have a small python script, i.e. a listener, work as well, which would let me avoid additional copy of NR. Done this before.

---

<div class="post-metadata">

**Author:** ![Jibun-no-Kage](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jibun-no-kage/32/99316_2.png) [@Jibun-no-Kage](https://discourse.nodered.org/u/Jibun-no-Kage)\
**Post date:** [31 December 2025 01:46 UTC](https://discourse.nodered.org/t/execute-systemctl-commands-from-nodered-on-remote-system/100044/6 "2025-12-31T01:46:28Z")

</div>

Nuts... it apparently is working consistently... I had a 'index' typo, so when I thought I was testing 'service 1' I as actually restarting 'service 0'... LOL. The test inject node was wrong.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [31 March 2026 01:46 UTC](https://discourse.nodered.org/t/execute-systemctl-commands-from-nodered-on-remote-system/100044/7 "2026-03-31T01:46:54Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
