When trying to connect to a VPN via command. And you receive config files like .ovpn
client .crt
and .key
or .p12
.
- First gather config files in a same directory. For this tuto, we assume that every config file is in the directory
~/Config/VPN/myVPN
. - Install
openvpn
package from official repositories.
on Ubuntu
sudo apt-get install openvpn
on Fedora
sudo dnf install openvpn
on MacOs
brew install openvpn
After instlling, make sure that the openvpn
command is available in the PATH
environment.
- Connection To connect to the VPN, go to the path where config files are stored and lauch the command.
cd ~/Config/VPN/myVPN
sudo openvpn --config downloaded-client-config.ovpn --pkcs12 vpn-client.domain.tld.p12
or in a signle command
sudo openvpn --config ~/Config/VPN/myVPN/downloaded-client-config.ovpn --pkcs12 ~/Config/VPN/myVPN/vpn-client.domain.tld.p12
If you see something like this
Thu Oct 22 12:10:46 2020 TUN/TAP device tun0 opened
Thu Oct 22 12:10:46 2020 TUN/TAP TX queue length set to 100
Thu Oct 22 12:10:46 2020 /sbin/ip link set dev tun0 up mtu 1500
Thu Oct 22 12:10:46 2020 /sbin/ip addr add dev tun0 10.***.***.***/27 broadcast 10.***.***.***
Thu Oct 22 12:10:46 2020 /sbin/ip route add ***.87.***.***/** via 192.***.***.***
Thu Oct 22 12:10:47 2020 /sbin/ip route add 0.0.0.0/1 via 10.***.***.***
Thu Oct 22 12:10:47 2020 /sbin/ip route add 128.0.0.0/1 via 10.***.***.***
Thu Oct 22 12:10:47 2020 WARNING: this configuration may cache passwords in memory -- use the auth-nocache option to prevent this
Thu Oct 22 12:10:47 2020 Initialization Sequence Completed
~/Config/VPN/myVPN
is the path do the directory where config files are stored. You need to change it accordingly to your situation.
You can even create an alias for that
alias connectMyVPN="sudo openvpn --config ~/Config/VPN/myVPN/downloaded-client-config.ovpn --pkcs12 ~/Config/VPN/myVPN/vpn-client.domain.tld.p12"
You can use alternatives for authentication.
sudo openvpn --config downloaded-client-config.ovpn --pkcs12 vpn-client.domain.tld.p12
sudo openvpn --config downloaded-client-config.ovpn --cert vpn-client.domain.tld.cert --key vpn-client.domain.tld.key
sudo openvpn --config downloaded-client-config.ovpn --auth-user-pass