Running sudo from exec

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?

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.


after U enter the password

is the next.

Sorry I can't be of more help.

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.

1 Like

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

# 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

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

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