# node red exec node without sudo

**URL:** <https://discourse.nodered.org/t/node-red-exec-node-without-sudo/55225>\
**Category:** General\
**Tags:** node-red-dashboard\
**Created:** [15 December 2021 09:13 UTC](https://discourse.nodered.org/t/node-red-exec-node-without-sudo/55225 "2021-12-15T09:13:53Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![shinjihun1](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shinjihun1/32/52669_2.png) [@shinjihun1](https://discourse.nodered.org/u/shinjihun1)\
**Post date:** [15 December 2021 09:13 UTC](https://discourse.nodered.org/t/node-red-exec-node-without-sudo/55225/1 "2021-12-15T09:13:53Z")

</div>

Dear all  
Hi!

node red exec node without sudo

pi@raspberrypi:~ $ bash hello.sh  
HELLO  
pi@raspberrypi:~ $ python hello.py  
HELLO  
pi@raspberrypi:~ $ sudo python hello.py  
Error opening audio device (null) for capture: Connection refused

Good working : src/programs/pocketsphinx\_continuous -lm hello.lm -dict hello.dic -verbose no -fwdtree no -fsgusefiller no -round\_filters no -topn 1 -ds 2 -maxwpf 5 -beam 1 -lpbeam 1 -logfn /dev/null -inmic yes

Node red Exec Node : python hello.py  
Error opening audio device (null) for capture: Connection refused

Could you check it!  
Please help me.

---

<div class="post-metadata">

**Author:** ![shinjihun1](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shinjihun1/32/52669_2.png) [@shinjihun1](https://discourse.nodered.org/u/shinjihun1)\
**Post date:** [15 December 2021 09:40 UTC](https://discourse.nodered.org/t/node-red-exec-node-without-sudo/55225/2 "2021-12-15T09:40:10Z")

</div>

How can I use shell script without sudo in Exec Node?

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [15 December 2021 09:42 UTC](https://discourse.nodered.org/t/node-red-exec-node-without-sudo/55225/3 "2021-12-15T09:42:06Z")

</div>

Welcome to the forum @shinjihun1

What is in hello.py?

Try in the exec node with the full path to the python command and the full path to the py file.

Also stop node red and start it again in a terminal and copy/paste the full output here. When pasting it use the `</>` button at the top of the forum entry window.

---

<div class="post-metadata">

**Author:** ![shinjihun1](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shinjihun1/32/52669_2.png) [@shinjihun1](https://discourse.nodered.org/u/shinjihun1)\
**Post date:** [15 December 2021 09:47 UTC](https://discourse.nodered.org/t/node-red-exec-node-without-sudo/55225/4 "2021-12-15T09:47:57Z")

</div>

Hi Colin

hello.py:  
import os  
os.system("sh hello.sh")

hello.sh:  
#!/bin/bash  
cd pocketsphinx-5prealpha  
sh hello.sh

CLI command:  
src/programs/pocketsphinx\_continuous -lm hello.lm -dict hello.dic -verbose no -fwdtree no -fsgusefiller no -round\_filters no -topn 1 -ds 2 -maxwpf 5 -beam 1 -lpbeam 1 -logfn /dev/null -inmic yes

CLI working is good.  
but in Exec Node(node-red), It does not work on that node as below.  
-Error opening audio device (null) for capture: Connection refused-

---

<div class="post-metadata">

**Author:** ![shinjihun1](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shinjihun1/32/52669_2.png) [@shinjihun1](https://discourse.nodered.org/u/shinjihun1)\
**Post date:** [15 December 2021 09:54 UTC](https://discourse.nodered.org/t/node-red-exec-node-without-sudo/55225/5 "2021-12-15T09:54:41Z")

</div>

on SSH CLI, the result is the same.  
sudo python hello.py : Error opening audio device (null) for capture: Connection refused  
sudo sh hello.sh : Error opening audio device (null) for capture: Connection refused

As a result, it is estimated that Sudo is automatically added to the Exec Node.  
I am thinking about if there is a way to delete Sudo in the Exec Node.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [15 December 2021 10:02 UTC](https://discourse.nodered.org/t/node-red-exec-node-without-sudo/55225/6 "2021-12-15T10:02:52Z")

</div>

> [@shinjihun1](#):
>
> it is estimated that Sudo is automatically added to the Exec Node.

It isn't, it will run as whatever user is running node red.

Please answer my other questions, that may give us useful information.

Also how did you install node red?

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [15 December 2021 11:09 UTC](https://discourse.nodered.org/t/node-red-exec-node-without-sudo/55225/7 "2021-12-15T11:09:08Z")

</div>

> [@shinjihun1](#):
>
> hello.sh:  
> #!/bin/bash  
> cd pocketsphinx-5prealpha  
> sh hello.sh

It is wrong to execute a shell script with **sh hello.sh**  
It is wrong to execute a shell script with **bash hello.sh**  
It is wrong to execute a shell script with **os.system("sh hello.sh")**

The first line of this script **#!/bin/bash** is _supposed_ to indicate to Linux that the script is to be interpreted by the bash shell.  
**sh** is not the same as **bash** , it is a different program with different syntax.

To execute a shell script:

1. Include a hashbang line which specifies the interpreter program, eg **#! /bin/bash**
2. Make it executable **chmod +x hello.sh**
3. Invoke it by unambiguously without **sh** or **bash** but with the full pathname **/home/pi/whatever/hello.sh**

Those comments hold for python scripts too, indeed any interpreted language.

What do you expect will happen when the script hello.sh which you posted above calls **sh hello.sh**?  
Is there another hello.sh in the directory pocketsphinx-5prealpha?  
Is that directory included in the environment variable $PATH?  
Is $PATH the same for the login shell and for the Node-Red exec node?

You can avoid these potential traps by properly and unambiguously invoking scripts.

> [@shinjihun1](#):
>
> Error opening audio device (null) for capture: Connection refused

You have not shown us the code which causes this error.

Do not use sudo unless the circumstances demand it. Any file that your program creates and leaves behind is storing up future difficulties.

---

<div class="post-metadata">

**Author:** ![shinjihun1](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shinjihun1/32/52669_2.png) [@shinjihun1](https://discourse.nodered.org/u/shinjihun1)\
**Post date:** [16 December 2021 00:56 UTC](https://discourse.nodered.org/t/node-red-exec-node-without-sudo/55225/8 "2021-12-16T00:56:18Z")

</div>

For the kind reply above,thank you.  
Please check above.

OS : Raspberry PI OS(32-bit) A port of debian bullseye with the raspberry Pi Desktop Release 2021-10-30  
sudo apt update  
sudo apt full-upgrade  
pi@raspberrypi:~ $ passwd  
Changing password for pi.  
Current password: raspberry  
New password: mrckorea  
Retype new password: mrckorea  
passwd: password updated successfully

Node-red install :  
bash \<(curl -sL [https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered](https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered)) : 설치명령  
sudo systemctl enable nodered.service -\> 자동실행  
node-red-start, node-red-stop  
node-red-dashboard 설치 : npm install node-red-dashboard

Node-red Password :  
node-red-stop  
Password : cd .node-red, sudo nano setting.js -\> PW 입력(adminAuth -- }.) ex) username(admin), PW(mrckorea)  
참조 동영상 : 2021-10-07 Raspberry Pi Node-RED ID Password.mp4  
sudo npm install -g node-red-admin  
node-red-admin hash-pw  
node-red-start

## Node-red Application : sudo apt-get install twinkle ~~sudo nano /etc/dhcpcd.conf : sudo raspi-config, 5. Localization Options ----, L2 Timezone, None of the above, GMT0 sudo apt install pimixer sudo apt-get install ntpdate : NTP 설치 TTS(Text to Speech), STT(Speech to Text) : sudo apt-get install espeak espeak -ven-us+f5 -s170 "Press Phone Number!" espeak -s 160 -p 95 -v ko+f3 "안녕하세요 말하는 음료수 자판기 입니다." espeak -s 160 -p 95 -v ko+f3 "원하는 전화 번호를 입력해 주세요." [https://www.youtube.com/watch?v=B5Cwi\_ZgPOc&ab\_channel=FedericoLomazzi](https://www.youtube.com/watch?v=B5Cwi_ZgPOc&ab_channel=FedericoLomazzi), [https://www.youtube.com/watch?v=qRzUr-HnUgw&ab\_channel=FedericoLomazzi](https://www.youtube.com/watch?v=qRzUr-HnUgw&ab_channel=FedericoLomazzi), sudo apt-get install autoconf libtool libportaudio0 libportaudio2 libportaudiocpp0 portaudio19-dev pulseaudio libpulse.dev libasound2-dev bison swig web 다운로드 1 : [Download sphinxbase-5prealpha.tar.gz (CMU Sphinx)](https://sourceforge.net/projects/cmusphinx/files/sphinxbase/5prealpha/sphinxbase-5prealpha.tar.gz/download) -o sphinxbase.tar.gz web 다운로드 2 : [Download pocketsphinx-5prealpha.tar.gz (CMU Sphinx)](https://sourceforge.net/projects/cmusphinx/files/pocketsphinx/5prealpha/pocketsphinx-5prealpha.tar.gz/download) -o pocketsphinx.tar.gz pocketsphinx.tar.gz sphinxbase.tar.gz 압축풀기 : tar -xzvf sphinxbase.tar.gz, tar -xzvf pocketsphinx.tar.gz cd sphinxbase-5prealpha/, ./configure, make, sudo make install cd ../pocketsphinx-5prealpha/, ./configure, make, sudo make install arecord comando.wav -f cd -r 16000 -c 1 -d 3 -vv : 녹음시험 aplay comando.wav : 재생 확인 src/programs/pocketsphinx\_continuous -infile comando.wav : 음성 TTS 변환 pocketsphinx\_continuous -inmic yes : 실시간 마이크 음성인식 arecord comando.wav -f cd -r 16000 -c 1 -d 3 -vv arecord attivazione.wav -f cd -r 16000 -c 1 -d 3 -vv src/programs/pocketsphinx\_continuous -lm 3891.lm -dict 3891.dic -infile attivazione.wav src/programs/pocketsphinx\_continuous -lm hello.lm -dict hello.dic -infile hello.wav : 실시간 시험 1 src/programs/pocketsphinx\_continuous -lm 3891.lm -dict 3891.dic -verbose no -fwdtree no -fsgusefiller no -round\_filters no -topn 1 -ds 2 -maxwpf 5 -beam 1 -lpbeam 1 -logfn /dev/null -inmic yes src/programs/pocketsphinx\_continuous -lm hello.lm -dict hello.dic -verbose no -fwdtree no -fsgusefiller no -round\_filters no -topn 1 -ds 2 -maxwpf 5 -beam 1 -lpbeam 1 -logfn /dev/null -inmic yes : 실시간 시험 2~~

Currently, there is one issue left.

pi@raspberrypi:~ $ sh hello.sh

HELLO  
HELLO  
HELLO  
HELLO

^C  
pi@raspberrypi:~ $ bash hello.sh

## HELLO HELLO ^C pi@raspberrypi:~ $

On CLI command : OK  
But in Exec Node(node-red), It does not work.  
As a result, it is estimated that Sudo is automatically added to the Exec Node.  
I am thinking about, there is a question about the contents related to the root/user authority setting when installing Nodered.

---

<div class="post-metadata">

**Author:** ![shinjihun1](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shinjihun1/32/52669_2.png) [@shinjihun1](https://discourse.nodered.org/u/shinjihun1)\
**Post date:** [16 December 2021 01:32 UTC](https://discourse.nodered.org/t/node-red-exec-node-without-sudo/55225/9 "2021-12-16T01:32:08Z")

</div>

On Stack [Overflow.com](http://Overflow.com), I found Set Node-red password in root mode by Knolleary.  
[node.js - Set Node-red password in root mode - Stack Overflow](https://stackoverflow.com/questions/54639343/set-node-red-password-in-root-mode)  
~~  
There are not two versions of Node-RED installed on the Raspberry Pi - you are running it in two different ways.  
Node-RED is installed as a system service. The service can be started and stopped using node-red-start and node-red-stop commands. By default, the service will run Node-RED as the pi user, and use /home/pi/.node-red as the user directory - where the settings.js file is located.  
You can manually run Node-RED by using the node-red command. Rather than start it as a service, it will run in the terminal you ran the command in. It uses ~/.node-red as the user directory. If you run it as the Pi user, that will be /home/pi/.node-red - the same as the service instance. If you run using sudo then you are running as the root user, so the user directory will be /root/.node-red. Following from that, the settings file it will use will be /root/.node-red/settings.js - so it is that file you would need to enable adminAuth in.  
You can confirm exactly what user directory and settings file it is using by viewing the log on start up where the full paths to both of these things is provided.  
Note: we strongly recommend not running as root if you do not need to.  
~~

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [16 December 2021 08:35 UTC](https://discourse.nodered.org/t/node-red-exec-node-without-sudo/55225/10 "2021-12-16T08:35:49Z")

</div>

You still haven't done what I asked, stop node red and start it again and post the terminal output here. When pasting it here use the `</>` button at the top of the forum entry window.

---

<div class="post-metadata">

**Author:** ![shinjihun1](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shinjihun1/32/52669_2.png) [@shinjihun1](https://discourse.nodered.org/u/shinjihun1)\
**Post date:** [16 December 2021 09:10 UTC](https://discourse.nodered.org/t/node-red-exec-node-without-sudo/55225/11 "2021-12-16T09:10:59Z")

</div>

I did a full reinstall of the SD card once more but it doesn't work.  
Node red Reinstalled : in User Mode, not admin.  
Could you check attached capture .  
node-red\_cap.PNG  
CLI\_Terminal.PNG

 ![CLI_Terminal](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/2/a2b21cac0c90a44a8c25fd13bb4a94f35ccb0196.png)  
 ![node-red_cap](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/9/f9215b7e265a5f790d676ccf5e3dbe0d9e91817c.png)

---

<div class="post-metadata">

**Author:** ![shinjihun1](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shinjihun1/32/52669_2.png) [@shinjihun1](https://discourse.nodered.org/u/shinjihun1)\
**Post date:** [16 December 2021 09:29 UTC](https://discourse.nodered.org/t/node-red-exec-node-without-sudo/55225/12 "2021-12-16T09:29:44Z")

</div>

Please let me know if there is a way to use CLI Terminal instead of Exec Node.  
Thanks!

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [16 December 2021 09:40 UTC](https://discourse.nodered.org/t/node-red-exec-node-without-sudo/55225/13 "2021-12-16T09:40:55Z")

</div>

Why is it so difficult to get you to respond to requests?  
For the third time, please stop node-red, start it in a terminal and copy/paste the output here. Stop and start it using  
`node-red-stop`  
`node-red-start`

When pasting use the `</>` button at the top of the forum entry window.

Also what have you now got in hello.sh?

Also please give all the debug nodes names so that it is clear which node the output is from

Also please show us how you have configured the exec node. A screenshot of that will do.

I can assure you that the exec node does not run as the user root, unless that is the user running node-red.

I notice above that you used sudo to edit settings.js. Never use sudo unless it is necessary. It will cause problems because you end up with files owned by root.

Please try and respond to all the requests.

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [16 December 2021 11:01 UTC](https://discourse.nodered.org/t/node-red-exec-node-without-sudo/55225/14 "2021-12-16T11:01:18Z")

</div>

> [@Colin](#):
>
> Why is it so difficult to get you to respond to requests?

Difficulty translating to/from Korean?

@shinjihun1 You seem to have ignored all the replies so far. Nevertheless:

Your script hello.sh, allegedly this:

```auto
#!/bin/bash
cd pocketsphinx-5prealpha
sh hello.sh

```

DOES NOT generate the output

```auto
HELLO
HELLO
HELLO

```

NOR the error

```auto
Error opening audio device (null) for capture: Connection refused

```

That's my last word.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [16 December 2021 11:46 UTC](https://discourse.nodered.org/t/node-red-exec-node-without-sudo/55225/15 "2021-12-16T11:46:44Z")

</div>

Also please try the command specifying the full path to the script, so the exec node should just specify something like  
`/home/pi/.node-red/hello.sh`  
Note, not `sh /home/pi/.node-red/hello.sh`

---

<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:** [14 February 2022 11:46 UTC](https://discourse.nodered.org/t/node-red-exec-node-without-sudo/55225/16 "2022-02-14T11:46:47Z")

</div>

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