OpenVPN AutoLogin Script

The following is an OpenVPN autologin script for my portable Raspberry Pi Kodi media center. It starts an OpenVPN connection on boot.



  • The Expect package
  • A folder containing an OpenVPN configuration file
  • A folder for the script (I put it in the same OpenVPN folder)


Script Creation

sudo apt-get install expect
sudo nano
chmod +x




set password "Password-For-OpenVPN-Connection\r"
set config "Path-To-OpenVPN-Config-File(*.ovpn)"

cd /Path-To-OpenVPN-Config-Folder

spawn openvpn $config
expect "Enter Private Key Password:"
send $password
expect eof


Add to Crontab

sudo crontab -e
@reboot /Path-To-Script-Folder/


Stop OpenVPN

sudo killall openvpn



References – 1, 2, 3, 4, 5, 6





OpenVPN AutoLogin Script
Scroll to top