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.

 

Dependencies

  • 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 autovpnscript.sh
chmod +x autovpnscript.sh

 

Contents

#!/usr/bin/expect

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
#interact
expect eof
exit

 

Add to Crontab

sudo crontab -e
@reboot /Path-To-Script-Folder/autovpn.sh

 

Stop OpenVPN

sudo killall openvpn

 

 

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

 

 

 

 

OpenVPN AutoLogin Script
Scroll to top