Ubuntu – Connect to VPN at login Ubuntu 18.04


I am looking for a way to enable me to start a vpn (OpenVPN) connection at the login screen to ensure mounted volumes on my home network connect when I'm out and about. I've not been able to find anything anywhere and was hoping the community could come up with an answer.

Best Answer

  • You can write a shell script that connects to openvpn and add this script to the system startup job list

    You will need root privileges for any the following. To get root, open a terminal and run the command

    sudo -i

    and the command prompt will change to '#' indicating that the terminal session has root privileges.

    Alternative #1: Add commands to /etc/rc.local

    vi /etc/rc.local

    with content like the following:

    # This script is executed at the end of each multiuser runlevel
    /path/to/my/script.sh || exit 1   # Added by me
    exit 0

    Alternative #2: Add an Upstart job (for systems older than 15.04)

    Create /etc/init/myjob.conf

    vi /etc/init/myjob.conf

    with content like the following

    description     "my job"
    start on startup
    exec /path/to/my/script.sh

    Alternative #3: Add an init script (obsolete)

    Create a new script in /etc/init.d/myscript.

    vi /etc/init.d/myscript

    (Obviously it doesn't have to be called "myscript".) In this script, do whatever you want to do. Perhaps just run the script you mentioned.


    Make it executable.

    chmod ugo+x /etc/init.d/myscript

    Configure the init system to run this script at startup.

    update-rc.d myscript defaults


  • Related Question