Import OpenVPN Config From Command Line with Network Manager

By | 2017/01/14

Network Manager on Linux has a command line interface which can do everything and more than the gui version. Here is how to import an openvpn config from the command line!


In this example, the openvpn config is a single file from pfSense (Inline Configurations > Other, in pfSense speak) which works well for Linux users.


Import as follows, where the filename in this example is is: bach-udp-1194-khmiller-config.ovpn

$ sudo nmcli connection import type openvpn file bach-udp-1194-khmiller-config.ovpn
Connection 'bach-udp-1194-khmiller-config' (5b04c610-ca37-4f76-bb61-07e9acdc603a) successfully added.

Done.


nmcli does have tab completion, so when in doubt hit tab as options are typed to see what is possible.

Ex:

$ sudo nmcli [TAB]
agent       connection  device      general     help        monitor     networking  radio       
$ sudo nmcli connection [TAB]
add      clone    delete   down     edit     export   help     import   load     modify   monitor  reload   show     up       
$ sudo nmcli connection edit [TAB]

etc.


6 thoughts on “Import OpenVPN Config From Command Line with Network Manager

  1. Utux

    You can import .ovpn files from the GUI. But sometimes it’s bugged, for example in Debian Jessie. Thanks for the CLI tip 🙂

    Reply
  2. Nebojša

    I cannot import split.ovpn.

    sudo nmcli connection import type openvpn filesplit.ovpn
    [sudo] password for nebojsa:
    Usage: nmcli connection { COMMAND | help }

    COMMAND := { show | up | down | add | modify | edit | delete | reload | load }

    show [–active] [[id | uuid | path | apath] ] …

    up [[id | uuid | path] ] [ifname ] [ap ]

    down [id | uuid | path | apath]

    add COMMON_OPTIONS TYPE_SPECIFIC_OPTIONS IP_OPTIONS

    modify [–temporary] [id | uuid | path] ([+|-]. )+

    edit [id | uuid | path]
    edit [type ] [con-name ]

    delete [id | uuid | path]

    reload

    load [ … ]

    Reply
    1. Nebojša

      Error: ‘import’ is not valid ‘connection’ command.

      Reply
  3. Maki

    This gives me an error on Debian 9:
    Error: failed to load VPN plugin: cannot load legacy-only VPN plugin “openvpn” for “/etc/NetworkManager/VPN/nm-openvpn-service.name”.

    Am I missing something here?

    Reply
  4. c. mosers

    I guess you could bat file in and use the vpn data as $1

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

Notify me of followup comments via e-mail. You can also subscribe without commenting.