Skip to content

Instantly share code, notes, and snippets.

@dleonard00
Created January 15, 2017 07:31
  • Star 37 You must be signed in to star a gist
  • Fork 8 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save dleonard00/fa482b4e803bf1f905526275c116c6d8 to your computer and use it in GitHub Desktop.
extract the certificate and key from an .ovpn file
#!/bin/bash
# This script will extract the certificate and key from an .ovpn file
# into their own files, which makes it possible to use them to configure
# the VPN using Ubuntu's network manager
# Usage example:
# >> ovpnconvert username.dev.ovpn
# You can keep following these instructions here:
# https://naveensnayak.wordpress.com/2013/03/04/ubuntu-openvpn-with-ovpn-file/
sed '1,/<ca>/d;/<\/ca>/,$d' $1 > $1.ca.crt
sed '1,/<cert>/d;/<\/cert>/,$d' $1 > $1.client.crt
sed '1,/<key>/d;/<\/key>/,$d' $1 > $1.client.key
sed '1,/<tls-auth>/d;/<\/tls-auth>/,$d' $1 > $1.ta.key
@tbrettschneider
Copy link

thx, you saved my day... worked like a charm!

@TheyCallMeLinux
Copy link

it's just perfect

@labbots
Copy link

labbots commented May 6, 2020

I have written a bash script that could split or merge OVPN config file. The code can be found at https://github.com/labbots/OVPN-Config-Manipulator

@whycaress
Copy link

I have written a bash script that could split or merge OVPN config file. The code can be found at https://github.com/labbots/OVPN-Config-Manipulator

didnt work

@labbots
Copy link

labbots commented May 26, 2020

@whycaress could you please raise an issue on the repository with details of what exactly was not working and sample file with no personal information and key so I could test the script.

@ghost-ng
Copy link

perfect - here for htb openvpn configuration with NetworkManager...THANK YOU!

@nfos
Copy link

nfos commented Apr 16, 2023

super for configuration opnsense / sophos sg

@LUIVLO
Copy link

LUIVLO commented Dec 24, 2023

Thanks ! Perfect for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment