Are there any risks for letting the beyond password to be used with no password?

It is a home computer, with no other users using it, I only use the single default created user when Ubuntu was installed.

I would like to don't have to write at all the sudo password for these commands:

echo 100 > /sys/class/backlight/intel_backlight/brightness

ethtool -s eth0 autoneg off speed 100 duplex full

dhclient eth0

apt-get update && upgrade && dist-upgrade -y

apt-get autoremove && remove && clean && autoclean -y

Thank you.

ANSWER: It seams that these steps resolved this case:

sudo su

Create /usr/local/bin/scriptname and write the beyond lines in it:


command in here without sudo

# the end of the script's name


Create /etc/sudoers.d/scriptname and write the following lines in it:

User_Alias scriptname=username
Cmnd_Alias scriptabreviaton=/home/globalisation/r
scriptname ALL=NOPASSWD: scriptabreviaton

Add at the end of /etc/sudoers the next two lines:

username ALL=(ALL:ALL) ALL
username ALL=(ALL:ALL) NOPASSWD: /usr/local/bin/scriptname


chown root:root /etc/sudoers.d/scriptname
chown root:root /usr/local/bin/scriptname
chmod 0700 /usr/local/bin/scriptname
chmod 0440 /etc/sudoers.d/scriptname


From the regular user name:

sudo /usr/local/bin/scriptname

It shouldn't ask for sudo password any more.

Everywhere when it is written "scriptname", "usernme", "scriptabreviaton" every each of them should be the same.


1 Answer 1


If you only need these exact commands you could create a script for each case under /usr/local/sbin and add those scripts into your sudoers file like:

you ALL=(ALL:ALL) NOPASSWD: /usr/local/sbin/backlight.sh
you ALL=(ALL:ALL) NOPASSWD: /usr/local/sbin/upgrade.sh

Don't forget to chown your scripts to root and also remove all unnecessary modes via chmod:

chown root:root /usr/local/sbin/backlight.sh
chmod go-rwx /usr/local/sbin/backlight.sh
  • I appreciate @Gábor Héja I am not so advanced and I have never used or made any script until now, can you please share a link where I can find out more please? And if you have some specific tips and tricks about add in the script those specific commands I am looking for please, indeed, I am looking just for only "these exact commands". Regards.
    – XPDIN
    Jun 8, 2017 at 14:12
  • 1
    Of course. It's actually pretty easy, start a text editor (as root as you're trying to save to /usr/local/sbin) place #!/bin/bash as the frist line, then an empty line, then your commands. Save it to the correct place, do the chown and chmod as in the earlier example and you're done. And a note, never edit the /etc/sudoers directly, always by running visudo. You can render your system unusable otherwise (due to even a simple typo). Jun 9, 2017 at 11:16
  • I appreciate @GáborHéja. Unfortunately it doesn't work, I've been very careful and check for many times everything to be in order, like you suggested, and none of the commands work without asking for the sudo password. Have you tried something like that yourself, and it worked? Could it influence in any way the fact that I use Lubuntu minimal installation ? Thank you.
    – XPDIN
    Jun 9, 2017 at 21:40
  • When i issue chmod as you described I got Permission denied
    – Salem F
    Sep 15, 2021 at 15:33
  • @SalemF, try to run as root or sudo chmod [...] Sep 16, 2021 at 7:14

Not the answer you're looking for? Browse other questions tagged .