I an trying to make a script that launches on boot to connect to my personal VPN.
I have an init file: /etc/init.d/vpnstartup
which calls my vpnon.sh script on boot with the commands:
case "$1" in
start)
su username -c $VPN_DIR/vpnon.sh
;;
in my script vpnon.sh there are commands that need root permissions to be executed:
sudo iptables -A INPUT -i pptp -j ACCEPT
sudo iptables -A OUTPUT -o pptp -j ACCEPT
I grant permissions of the vpnstartup init file and the vpnon.sh script with chmod 775 when I try out my init file by calling it using ./vpnstartup start
I get the following error when the sudo iptables command gets called
sudo: no tty present and no askpass program specified
sudo: no tty present and no askpass program specified
what I think is happening is the sudo command requires an input password but has no way to get it.
The only solution I found was adding the NOPASSWD :ALL option
to the sudoers file under my user name.
I don't want to do this method for security reasons if there is a better solution.
Please let me know if you can help me with this problem; I have spent many hours on it.
su
from root in your init script to run a script that then requires you tosudo
back to root: can't you organize your script(s) to avoid that?