For command-line applications that do not require GUI, it is sufficient to place the call to them into
/etc/rc.local , which already runs as root, thus does not need
sudo. Below is example of my own
/etc/rc.local which I use for starting two monitoring scripts.
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
# In order to enable or disable this script just change the execution
# By default this script does nothing.
For GUI applications, you would need to take a different approach. You would need to open Startup Applications app, and add the following command:
bash -c "sleep 10;gksu /usr/bin/my_vpn_program"
What this does is gives GUI sufficient time to start, 10 seconds, then will bring up password dialog and if you enter password properly, will launch your command. Effectively this is a mini bash script. You can use
pkexec instead, and some might even say
pkexec is recommended instead of
Alternatively, if you don't want to enter password every time, you can allow your user run this particular command with root privileges without authentication. For that you need to edit
/etc/sudoers file. WARNING: it is recommended that you use
sudo visudo to edit the file from terminal. Below is example of how I use the same setting with
# Allow using pm-suspend for my user without password
my_username_here ALL = NOPASSWD: /usr/sbin/pm-suspend
This line should be appended to the end of
/etc/sudoers file and saved. Note, that you still need to append
gksu to the beginning of each command that you set up. Thus, you would need to use the same
bash command I showed previously.