# Running sudo from exec

**URL:** https://discourse.nodered.org/t/running-sudo-from-exec/54787
**Category:** General
**Created:** [6 December 2021 20:19 UTC](https://discourse.nodered.org/t/running-sudo-from-exec/54787 "2021-12-06T20:19:50Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![nygma2004](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nygma2004/32/1308_2.png) [@nygma2004](https://discourse.nodered.org/u/nygma2004)
#### Post date: [6 December 2021 20:19 UTC](https://discourse.nodered.org/t/running-sudo-from-exec/54787/1 "2021-12-06T20:19:50Z")

</div>

I think this is going to be generic Linux question, but I don't know the answer to it: I am setting up my new Node-Red server which is not a RaspberryPI, but a PC running Debian.

Back in the Rpi days I used to run command from exec with sudo. Here I added my user (which also runs Node-Red) to the sudoer list, so I can run thing like `sudo hddtemp /dev/sda` after I enter the password. But I am guessing because of this the same command from exec fails.

What is the proper way of fixing this?

---

<div class="post-metadata">

### Author: ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)
#### Post date: [6 December 2021 20:42 UTC](https://discourse.nodered.org/t/running-sudo-from-exec/54787/2 "2021-12-06T20:42:02Z")

</div>

If you have added the user to the `sudoer list`, you shouldn't need to do the `sudo` at the start.

That's the first _problem_ I can see.

The

> after U enter the password

is the next.

Sorry I can't be of more help.

---

<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: [6 December 2021 20:54 UTC](https://discourse.nodered.org/t/running-sudo-from-exec/54787/3 "2021-12-06T20:54:49Z")

</div>

You need to use  
`sudo visudo`  
to tell the system that the user can run that command with sudo without the need to enter a password. I always have to look up the syntax. If you Google for visudo you should be able to find examples of how to do it.

---

<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: [6 December 2021 21:19 UTC](https://discourse.nodered.org/t/running-sudo-from-exec/54787/4 "2021-12-06T21:19:03Z")

</div>

As Colin mentions, the "proper" way is to create passwordless sudo exemptions for specific commands.

Here is an example from my own system (the contents of `sudo visudo`). `home` is the user running Node-RED. The last line lets the `home` user run anything under `sudo` (with a password) but can also use `sudo` without a password for a specific set of commands

```auto
#
# This file MUST be edited with the 'visudo' command as root.
#
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
#
# See the man page for details on how to write a sudoers file.
#
Defaults env_reset,timestamp_timeout=-1
Defaults mail_badpass
Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

# Host alias specification

# User alias specification

# Cmnd alias specification

# User privilege specification
root ALL=(ALL:ALL) ALL

# Allow members of group sudo to execute any command
%sudo ALL=(ALL:ALL) ALL

# See sudoers(5) for more information on "#include" directives:

#includedir /etc/sudoers.d

home ALL=(ALL) NOPASSWD:/usr/bin/apt update, /usr/bin/apt list --upgradable, \
     /usr/bin/apt upgrade, /usr/bin/systemctl status *.service, \
     /usr/bin/systemctl restart nrmain, /usr/bin/du -sh /var/lib/influxdb/data/, \
     /usr/bin/du -sh /var/lib/influxdb/* \
     /usr/sbin/dumpe2fs *, /usr/bin/systemctl show nrmain

```

---

<div class="post-metadata">

### Author: ![nygma2004](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nygma2004/32/1308_2.png) [@nygma2004](https://discourse.nodered.org/u/nygma2004)
#### Post date: [7 December 2021 07:08 UTC](https://discourse.nodered.org/t/running-sudo-from-exec/54787/5 "2021-12-07T07:08:48Z")

</div>

> [@TotallyInformation](#):
>
> `ALL=(ALL) NOPASSWD:/usr/bin/apt update`

Thanks a lot for these details. Now I understand how this works. I edited my nopasswd details and it works now.

---

<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: [21 December 2021 07:09 UTC](https://discourse.nodered.org/t/running-sudo-from-exec/54787/6 "2021-12-21T07:09:35Z")

</div>

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