
{"id":50852,"date":"2026-03-30T12:34:16","date_gmt":"2026-03-30T12:34:16","guid":{"rendered":"https:\/\/ubuntuhandbook.org\/?p=50852"},"modified":"2026-03-30T12:34:16","modified_gmt":"2026-03-30T12:34:16","slug":"fix-openvpn-connection-fail-in-ubuntu-26-04","status":"publish","type":"post","link":"https:\/\/ubuntuhandbook.org\/index.php\/2026\/03\/fix-openvpn-connection-fail-in-ubuntu-26-04\/","title":{"rendered":"Fix OpenVPN Immediate Connection Failure in Ubuntu 26.04"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-thumbnail wp-image-43605\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2023\/01\/network-icon-250x250.webp\" alt=\"\" width=\"250\" height=\"250\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2023\/01\/network-icon-250x250.webp 250w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2023\/01\/network-icon-300x300.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2023\/01\/network-icon-600x600.webp 600w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2023\/01\/network-icon-768x768.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2023\/01\/network-icon.webp 1200w\" sizes=\"auto, (max-width: 250px) 100vw, 250px\" \/><\/p>\n<p>In Ubuntu 26.04 (Beta so far), OpenVPN connection does not work out-of-the-box due to a bug in AppArmor. Here&#8217;s a quick workaround to fix the issue.<\/p>\n<p>For security reason, Ubuntu by default uses AppArmor (Application Armor), a Linux Kernel security mode, to restrict programs&#8217; capabilities for file access, networking and permissions.<\/p>\n<p><!--more--><\/p>\n<p>It uses a list of profiles under <code>\/etc\/apparmor.d<\/code> directory to define and restrict the applications&#8217; capabilities. And, AppArmor in Ubuntu since 25.04 added a profile for openvpn to restrict its capabilities.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-50853\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2026\/03\/openvpn-connectionfail.webp\" alt=\"\" width=\"637\" height=\"196\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2026\/03\/openvpn-connectionfail.webp 637w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2026\/03\/openvpn-connectionfail-300x92.webp 300w\" sizes=\"auto, (max-width: 637px) 100vw, 637px\" \/><\/p>\n<p>When import or create a OpenVPN connection, and then connect to the VPN, the Network Manager will copy the certificate keys into memory (<code>\/run<\/code> directory). However, the new AppArmor profile in 26.04 does not allow <code>openvpn<\/code> to access the files there.<\/p>\n<p>So, it immediately return &#8220;connection failed&#8221;, and the <code>\/var\/log\/syslog<\/code> file will show you something like below:<\/p>\n<blockquote><p><i>2026-03-30T04:47:32.996275-07:00 Resolute nm-openvpn[70487]: Cannot pre-load keyfile (\/run\/NetworkManager\/cert\/NVIziP)<br \/>\n2026-03-30T04:47:32.996332-07:00 Resolute nm-openvpn[70487]: Exiting due to fatal error<br \/>\n2026-03-30T04:47:32.996558-07:00 Resolute kernel: audit: type=1400 audit(1774871252.994:2433): apparmor=&#8221;DENIED&#8221; operation=&#8221;open&#8221; class=&#8221;file&#8221; profile=&#8221;openvpn&#8221; name=&#8221;\/run\/NetworkManager\/cert\/NVIziP&#8221; pid=70487 comm=&#8221;openvpn&#8221; requested_mask=&#8221;r&#8221; denied_mask=&#8221;r&#8221; fsuid=0 ouid=0<\/i><\/p><\/blockquote>\n<p>Apparently, the issue is that AppArmor denied openvpn from accessing the <code>\/run\/NetworkManager\/cert\/NVIziP<\/code> file.<\/p>\n<div id=\"attachment_50854\" style=\"width: 620px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-50854\" class=\"size-large wp-image-50854\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2026\/03\/openvpn-denied-700x437.webp\" alt=\"\" width=\"610\" height=\"381\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2026\/03\/openvpn-denied-700x437.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2026\/03\/openvpn-denied-300x187.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2026\/03\/openvpn-denied-768x480.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2026\/03\/openvpn-denied.webp 1002w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><p id=\"caption-attachment-50854\" class=\"wp-caption-text\">AppArmor denied openvpn from accessing the key file<\/p><\/div>\n<p><b>And, the solution is simply add read access to the files under <code>\/run\/NetworkManager\/cert<\/code> directory for openvpn<\/b>.<\/p>\n<p>It&#8217;s said that the issue has been fixed in version <code>5.0.0~beta1-0ubuntu3<\/code> according to this <a href=\"https:\/\/bugs.launchpad.net\/ubuntu\/+source\/network-manager-openvpn\/+bug\/2143810\" target=\"_blank\" rel=\"noopener\">bug report<\/a>, though it still occurs in my case, so I write a workaround via the steps below.<\/p>\n<p><b>1. Edit the AppArmor profile.<\/b><\/p>\n<p>First, press <code>Ctrl+Alt+T<\/code> to open terminal. When terminal opens, run the command below to navigate to AppArmor config files directory and list all the default profiles.<\/p>\n<pre>cd \/etc\/apparmor.d\/ &amp;&amp; ls<\/pre>\n<p>There you&#8217;ll see the <code>openvpn<\/code> config file.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-50855\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2026\/03\/apparmor-openvpnconf-700x550.webp\" alt=\"\" width=\"610\" height=\"479\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2026\/03\/apparmor-openvpnconf-700x550.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2026\/03\/apparmor-openvpnconf-300x236.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2026\/03\/apparmor-openvpnconf-768x603.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2026\/03\/apparmor-openvpnconf.webp 1042w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/p>\n<p>To edit it, run command:<\/p>\n<pre>sudo gnome-text-editor \/etc\/apparmor.d\/openvpn<\/pre>\n<p>Tips: Here <code>gnome-text-editor<\/code> is for the default GNOME, replace it with your desktop text editor, or use <code>nano<\/code> that works in most desktops.<\/p>\n<p><b>2. Add read access<\/b><\/p>\n<p>When file opens in text editor, add the line <code>file r \/run\/NetworkManager\/cert\/*,<\/code> between the main section, so it will look like:<\/p>\n<pre>profile openvpn \/usr\/sbin\/openvpn flags= ( ... ) {\r\n    ...\r\n    ...\r\n    <b>file r \/run\/NetworkManager\/cert\/*,<\/b>\r\n    ...\r\n    ...\r\n}<\/pre>\n<p>It tells to allow read access to any files under <code>\/run\/NetworkManager\/cert<\/code> directory. <b>Remember to add comma (,) in line end.<\/b><\/p>\n<p>To be strict, use <b>file r @{run}\/NetworkManager\/cert\/@{rand6},<\/b> instead, so it only has read access to any 6-character name files under that directory.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-50856\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2026\/03\/config-openvpnapparmor-700x526.webp\" alt=\"\" width=\"610\" height=\"458\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2026\/03\/config-openvpnapparmor-700x526.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2026\/03\/config-openvpnapparmor-300x225.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2026\/03\/config-openvpnapparmor-768x577.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2026\/03\/config-openvpnapparmor.webp 885w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/p>\n<p><b>3. Apply Changes<\/b><\/p>\n<p>After made changes to the AppArmor profiles, restart the service to reload the rules:<\/p>\n<pre>sudo systemctl restart apparmor.service<\/pre>\n<p>Finally, try to connect to your OpenVPN and hope it works!<\/p>","protected":false},"excerpt":{"rendered":"<p>In Ubuntu 26.04 (Beta so far), OpenVPN connection does not work out-of-the-box due to a bug in AppArmor. Here&#8217;s a quick workaround to fix the issue. For security reason, Ubuntu by default uses AppArmor (Application Armor), a Linux Kernel security mode, to restrict programs&#8217; capabilities for file access, networking and permissions.<\/p>\n","protected":false},"author":1,"featured_media":43605,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[1317,2059],"class_list":["post-50852","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-howtos","tag-network","tag-vpn"],"_links":{"self":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/posts\/50852","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/comments?post=50852"}],"version-history":[{"count":0,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/posts\/50852\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/media\/43605"}],"wp:attachment":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/media?parent=50852"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/categories?post=50852"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/tags?post=50852"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}