Dec 03 12:11:28 pi wg-quick[124827]: wg-quick: `/etc/wireguard/wg0.conf' does not exist
Dec 03 12:11:28 pi systemd[1]: wg-quick@wg0.service: Main process exited, code=exited, status=1/FAILURE
Dec 03 12:11:28 pi systemd[1]: wg-quick@wg0.service: Failed with result 'exit-code'.
Dec 03 12:11:28 pi systemd[1]: Failed to start wg-quick@wg0.service - WireGuard via wg-quick(8) for wg0.
# ll /etc/wireguard/wg0.conf
-rw-r--r--. 1 root root 233 Dec 3 12:05 /etc/wireguard/wg0.conf
# ll $(which wg-quick)
-rwxr-xr-x. 3 root root 13464 Jan 1 1970 /usr/bin/wg-quick
Solution: start firewalld and bring up the wireguard interface before trying to enable the service
systemctl start firewalld
wg-quick up wg0
systemctl enable wg-quick@wg0
Unsolving: the above command completed, but the service still doesn’t start
# systemctl status wg-quick@wg0.service
× wg-quick@wg0.service - WireGuard via wg-quick(8) for wg0
Loaded: loaded (/usr/lib/systemd/system/wg-quick@.service; enabled; preset: disabled)
Drop-In: /usr/lib/systemd/system/service.d
└─10-timeout-abort.conf
Active: failed (Result: exit-code) since Sun 2023-12-03 15:33:44 IST; 18s ago
Docs: man:wg-quick(8)
man:wg(8)
https://www.wireguard.com/
https://www.wireguard.com/quickstart/
https://git.zx2c4.com/wireguard-tools/about/src/man/wg-quick.8
https://git.zx2c4.com/wireguard-tools/about/src/man/wg.8
Process: 411182 ExecStart=/usr/bin/wg-quick up wg0 (code=exited, status=1/FAILURE)
Main PID: 411182 (code=exited, status=1/FAILURE)
CPU: 21ms
Dec 03 15:33:44 pi systemd[1]: Starting wg-quick@wg0.service - WireGuard via wg-quick(8) for wg0...
Dec 03 15:33:44 pi wg-quick[411182]: wg-quick: `/etc/wireguard/wg0.conf' does not exist
Dec 03 15:33:44 pi systemd[1]: wg-quick@wg0.service: Main process exited, code=exited, status=1/FAILURE
Dec 03 15:33:44 pi systemd[1]: wg-quick@wg0.service: Failed with result 'exit-code'.
Dec 03 15:33:44 pi systemd[1]: Failed to start wg-quick@wg0.service - WireGuard via wg-quick(8) for wg0.
root@pi:/etc/wireguard# semanage fcontext -a -t wireguard_t '/etc/wireguard(/.*)?'
ValueError: Type wireguard_t is invalid, must be a file or device type
/usr/bin/wg-quick is just a shell script using [[ -e $CONFIG_FILE ]].
Are you tab-completing the path to wg0.conf? Is it possible that there’s something like a non-printable character hidden in there? Slipping a ZWNJ (U+200C) into the filename yields the results you’re seeing.
I had this problem a while ago and was told that a non-functional systemd unit was acceptable, because they were other options, and supposedly using the wg-quick systemd unit was going “against best practices”, for some unexplained reason.
It turns out that i had a SELinux context issue, and running restorecon -R -v /etc/wireguard/ fixed it:
Relabeled /etc/wireguard/wg0.conf from unconfined_u:object_r:user_home_t:s0 to unconfined_u:object_r:etc_t:s0
I wonder if like me, you’d initially created the wireguard config file in your home directory @bennyp and then copied it into /etc/wireguard.
So, in summary:
chmod 0700 /etc/wireguard/
chown root: /etc/wireguard/
chmod 0600 /etc/wireguard/*
restorecon -R -v /etc/wireguard/
While rpm --restore wireguard-tools won’t work on an ostree-based system like Silverblue as already pointed out, I just tried running restorecon -R -v /etc/wireguard/ and it works.
You probably could have confirmed yours was selinux related by temporarily setting selinux to permissive instead of enforcing to test and see if that allowed wireguard to function properly.
That could have been done using sudo setenforce 0 to put it into permissive mode and then use sudo setenforce 1 to restore it to enforcing mode.
I don’t recommend disabling SELinux as it has a ton a weird consequences on the system and can create more problems.
If you have permissions issues and suspect this is due to SELinux, you should be able to find entries in the audit log /var/log/audit/audit.log or in the journal.
I agree 100% Note that I did not recommend disabling it.
I instead recommended temporarily putting it into permissive mode to see if selinux was blocking wireguard for testing purposes.
Unless I am totally misunderstanding the way selinux works, permissive mode does not disable anything. It does allow things to continue that otherwise would be blocked by selinux in enforcing mode and provides a warning in the journalctl logs. All other functions of selinux remain active including the labeling of files with selinux context, etc. When a reboot is done or when the setenforce command is used to return to enforcing mode things resume as normal.
I have never seen any problems with using permissive mode for the entire system on a temporary basis. It would seem much more complex and possibly even beyond my expertise as an experienced user to do as you suggest here.
SELinux is complex and I only use enforcing (or occasionally permissive for testing purposes) since I have no desire to dig into how it works and manage specific items of that nature.