I want to execute a script that requires root privileges without entering a password. There are similar questions/answers but non seems to work for me.
I placed my script in /home/kf/bin (I added the bin dir myself) and included this directory in my path so I can run it from everywhere.
#! /bin/sh sudo fstrim -v /
I changed the ownership of the script to
sudo chown root:root /home/kf/bin/trim.sh
and made it executable
sudo chmod 700 /home/kf/bin/trim.sh
next I added a line to my sudoers file with
kf ALL=(ALL) NOPASSWD: /home/kf/bin/trim.sh
When I login again and execute the script with
trim I still need to enter my password. I know I can make a cron for this but I also want to be able to execute the script manually without entering my password. Any help appreciated.
My sudoers file looks like this:
Defaults env_reset Defaults mail_badpass Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin: /usr/bin:/sbin:/bin" root ALL=(ALL:ALL) ALL kf ALL=(ALL) NOPASSWD: /home/kf/bin/trim.sh %admin ALL=(ALL) ALL %sudo ALL=(ALL:ALL) ALL