You run the VPN client with sudo. It signs in fine. Then wg-quick dies with "permission denied" on a config file that root can obviously read. File permissions are not the problem. AppArmor is, and it ignores who you are.
This guide covers diagnose, fix, verify, and rollback. The hook is a real report: the Mysterium VPN command-line client failing on Ubuntu. The method works for any WireGuard-based client that hands wg-quick a config file from an unusual location.
What happened with Mysterium (as reported)
An It's FOSS article on the Mysterium VPN Linux CLI describes the failure. The reviewer tested v0.3.0 on Ubuntu 26.04 LTS. Sign-in worked, but connecting did not. The client kept asking to run the auth command again, asked for sudo repeatedly, and failed to save the sign-in state. With sudo, the connect command ended in a permission denied error from wg-quick on one of the client's config files. (source)
The developers sent a fix that adds read access for the client's config folder to the AppArmor profile wg-quick uses. According to the article, the client then connected and stayed signed in across reboots.
Treat that as a report, not a verified result. Nobody has independently confirmed it, and the commands below have not been run on Ubuntu 24.04 or 26.04 for this article. The expected output shown later is illustrative.
Why sudo does not help
AppArmor is mandatory access control. The kernel checks what a confined program may touch by profile, not by user. If the wg-quick profile does not list a path, a root-owned process running under that profile still gets denied.
That explains the confusing symptom. The file exists, root owns it, and wg-quick still says no. A VPN client that keeps its configs in its own directory, such as a per-user folder in root's home when run with sudo, is exactly what a stock profile will not anticipate.
Prerequisites
Check these before you change anything.
- You are on Ubuntu with AppArmor active. Run
sudo aa-statusand confirm it reports the module is loaded. - wg-quick is installed. Run
command -v wg-quick. On Ubuntu it ships in the wireguard-tools package. - A profile file exists at /etc/apparmor.d/wg-quick. Run
ls -l /etc/apparmor.d/wg-quick. If it is missing, this guide does not apply to your system. - You know the exact config path that fails. The error message from the client or wg-quick usually prints it.
One more check matters. The override only takes effect if the main profile includes the local file. Run:
grep -n 'local' /etc/apparmor.d/wg-quick
Look for a line like include if exists <local/wg-quick>. If it is absent, a file in /etc/apparmor.d/local/ does nothing. The Mysterium report implies the include exists on that setup, but check yours.
Step 1: Confirm AppArmor is blocking wg-quick
Reproduce the failure, then search the kernel log right away:
sudo journalctl -k --since '10 minutes ago' | grep -i denied
Or use dmesg:
sudo dmesg | grep -i apparmor | grep -i denied
You want a line with apparmor="DENIED", profile="wg-quick", and comm="wg-quick". Here is an illustrative example with a made-up path: We cover related ground in wine on arm64 avx support: will your windows apps run? explained.
apparmor="DENIED" operation="open" profile="wg-quick" name="/etc/example-vpn/configs/wg0.conf" comm="wg-quick" requested_mask="r" denied_mask="r"
Two fields tell you what to write. The name= field is the path to allow. The requested_mask field says which permission is missing. r means read, so a read-only rule is enough.
If auditd is installed, denials may land in /var/log/audit/audit.log instead of the journal. If you see no DENIED entries at all, stop here. Your problem is something else, such as a wrong file mode or a missing file.
Step 2: Back up, then write a minimal local override
Local overrides exist so you do not have to edit the packaged profile. Package updates can overwrite /etc/apparmor.d/wg-quick, but they leave files in local/ alone.
The It's FOSS article shows its commands flattened onto one line, heredoc included. That will not work as typed, because the heredoc body and the closing EOF each need their own line. Write it like this, and replace the placeholder path with the one from your DENIED message:
sudo cp -a /etc/apparmor.d/local/wg-quick /etc/apparmor.d/local/wg-quick.bak 2>/dev/null
sudo tee /etc/apparmor.d/local/wg-quick > /dev/null <<'EOF'
/etc/example-vpn/configs/ r,
/etc/example-vpn/configs/*.conf r,
EOF
The first line saves any existing local file, and the error is silenced if there is none. Be careful: tee without -a overwrites the file. If you already had custom rules there, append with tee -a instead and remove nothing.
The first rule lets wg-quick list the directory. The second lets it read .conf files directly inside it. Both are read-only, and * does not recurse into subfolders.
Adapt the path, do not copy Mysterium's
The report used /root/.config/mystvpn/wireguard/configs/ and its *.conf files. That path is specific to Mysterium running under sudo. Your client will use something different. Take the path from your own DENIED line, and keep it as narrow as the log allows. Avoid /** r or rw rules. They turn a small hole into a large one.
Step 3: Reload the profile
sudo apparmor_parser -r /etc/apparmor.d/wg-quick
Silence means success. A syntax error prints a message with a line number, and the old profile stays loaded. Then confirm the file contents and the profile state: See check which radeon driver your old gpu uses on linux: the details for additional background.
sudo cat /etc/apparmor.d/local/wg-quick
sudo aa-status | grep wg-quick
You should see your two rules, and wg-quick listed among the loaded profiles.
Step 4: Verify the tunnel
Retry the connection the way you did before. For Mysterium that is sudo mystvpn connect with your country options, per the article. For a plain WireGuard setup, run sudo wg-quick up wg0.
Then check three things:
sudo wg show
ip -brief address show
curl -4 https://ifconfig.me
wg show should list an interface with a recent handshake. The address output should show the tunnel interface up. The public IP should differ from your normal one. Also watch the journal for new DENIED lines. A second denial on a different path means you need another narrow rule, added the same way.
Also read: enable hdr in mpv on wayland: config, checks, fixes
Rollback
If the change did nothing, or you want it gone:
sudo mv /etc/apparmor.d/local/wg-quick.bak /etc/apparmor.d/local/wg-quick
sudo apparmor_parser -r /etc/apparmor.d/wg-quick
If there was no backup because the file did not exist before, delete it with sudo rm /etc/apparmor.d/local/wg-quick instead, then run the same reload. Confirm with sudo aa-status | grep wg-quick and retest. The reload is what makes the rollback real. Editing the file alone changes nothing in the kernel.
Troubleshooting
| Symptom | Likely cause |
| --- | --- |
| Client repeatedly asks to re-authenticate or run sudo | It cannot save or read state because wg-quick fails underneath. The Mysterium report saw this before the override. Check the journal for DENIED. |
| Permission denied as root, with a DENIED line | The profile lacks a read rule for the path in name=. |
| Permission denied, no DENIED line | Not AppArmor. Check the file exists, its mode, and the path. |
| Rule added, still denied | Profile not reloaded, or the main profile does not include local/wg-quick. Run the reload and the grep from the prerequisites. |
| apparmor_parser prints a syntax error | Missing trailing comma, or a stray character from a flattened paste. Rewrite the file line by line. |
| New DENIED on a different path | The client touches more than one location. Add one more narrow rule. |
Inspect installers before you run them
The Mysterium article installs the CLI with a curl ... | bash one-liner from its GitHub releases page. Do not pipe anything into a root shell blindly. Download the script, read it, then run it:
curl -fsSLo install.sh https://github.com/mysteriumnetwork/mysteriumvpncli/releases/latest/download/install.sh
less install.sh
bash install.sh
This matters more here, because you are about to loosen a security profile on a machine that handles your network traffic.
What to expect next
A read-only rule like this should survive reboots and routine package updates, since local overrides live outside the packaged profile. The Mysterium report says the client stayed signed in across reboots after the change. A future Ubuntu release could change the wg-quick profile, so recheck after a release upgrade if the error returns. If a client's developers move where it stores configs, the DENIED line will show the new path, and the same four steps apply.



