cloudflared icon indicating copy to clipboard operation
cloudflared copied to clipboard

🐛Cannot install cloudflared service on Linux

Open e-dervieux opened this issue 1 year ago • 6 comments

Following this documentation, one should be able to install cloudflared and make it run as a service by running: cloudflared service install followed by systemctl start cloudflared.

The issue is that the former command tries to write to /etc which belongs to root and thus fails miserably:

> cloudflared service install
failed to copy /home/XXX/.cloudflared/config.yml to /etc/cloudflared/config.yml: open /etc/cloudflared/config.yml: permission denied

However, running it with sudo also fails, because then the installer tries to look for a config.yml file inside root's home, and such file does not exist:

> sudo cloudflared service install
Cannot determine default configuration path. No file [config.yml config.yaml] in [~/.cloudflared ~/.cloudflare-warp ~/cloudflare-warp /etc/cloudflared /usr/local/etc/cloudflared]

Note: the tunnel runs fine otherwise when launched from the terminal with cloudflared tunnel run YYY so this is probably not a .cert or config file-related issue.

Environment and versions

  • OS: Ubuntu 24.04.2 LTS
  • Architecture: AMD64
  • Version: cloudflared version 2025.4.0 (built 2025-04-02-1524 UTC

e-dervieux avatar Apr 26 '25 16:04 e-dervieux

As a workaround, we can create the file /etc/systemd/system/cloudflared_tun.service containing the following lines (see here and there):

[Unit]
Description=Cloudflare tunneling for <your app name>
After=network-online.target
StartLimitIntervalSec=0

[Service]
Type=simple
Restart=always
RestartSec=5
User=<user_name>
ExecStart=cloudflared tunnel run <your tunnel name>

[Install]
WantedBy=multi-user.target

You can test that the service is properly configured by starting it with sudo systemctl restart cloudflared_tun, and enable it to run at boot with sudo systemctl enable cloudflared_tun. Works like a charm on Ubuntu 24.04.2 LTS! 🙂

e-dervieux avatar May 11 '25 13:05 e-dervieux

Hi, Thank you for reaching out. This problem seems to be more related with the current permissions your user has on the file system of the machine you are running, and not to an issue on cloudflared. Since you already found a workaround for it I will close this.

jcsf avatar Jun 12 '25 12:06 jcsf

@jcsf, I think you might not have read thoroughly the issue that I reported in the first place.

IMHO, this is indeed a problem with cloudflared and not with the user's permissions: the cloudflared service install needs to be run by someone right? Would it be the current user, or root (with sudo).

  • if you run it using the current user, it fails because it tries to write in /etc/cloudflared/, which is by no mean intended to belong to the current user (/etc/ and its subfolders belongs to root in most UNIX system). Thus, the command fails, because the cloudflared command was run by user. A possible workaround could be to make /etc/cloudflared/ writable by current user, which does not seem like a good idea.
  • if you run it as superuser root (using sudo), cloudflared thus has the permission to write to /etc/cloudflared/, but seeks the config file in root's home folder instead of the user's, which is also problematic, since several users on a given system might want to use dedicated config files.

To me, this is very much a bug, because cloudflared does not behave as it is said to do in the documentation (documentation <-> actual behaviour mismatch).


That being said, you could either:

  • change the documentation to clearly state that either (1) the current user should have write permission on /etc/cloudflared/ or that (2) the config.yml file should be in root's home folder and that the cloudflared service install command should be launched with sudo.
  • change the command behaviour so that it writes in the current user's folder and does not need to be run with sudo, or can be run with sudo but with an extra argument to specify the config file path.

Note: I could not find any documentation for the cloudflared service install command. Man page for cloudflared is extremely succinct, and cloudflared service install --help does not help. I also tried to do a search in Cloudflare's documentation without success. If you know more about that, or about how to specify a given config file when using the cloudflared service install command, please let me know.

e-dervieux avatar Jun 12 '25 13:06 e-dervieux

As a workaround, we can create the file /etc/systemd/system/cloudflared_tun.service containing the following lines (see here and there):

[Unit]
Description=Cloudflare tunneling for <your app name>
After=network-online.target
StartLimitIntervalSec=0

Service]
Type=simple
Restart=always
RestartSec=5
User=manu
ExecStart=cloudflared tunnel run <your tunnel name>

[Install]
WantedBy=multi-user.target

You can test that the service is properly configured by starting it with sudo systemctl restart cloudflared_tun, and enable it to run at boot with sudo systemctl enable cloudflared_tun. Works like a charm on Ubuntu 24.04.2 LTS! 🙂

In case the others happend to copy paste your code, it suppose tp be [Service] and User=<user_name>

Arinomo avatar Jul 23 '25 20:07 Arinomo

@Arinomo thanks for watching out, I corrected it in the original answer! :)

e-dervieux avatar Jul 24 '25 06:07 e-dervieux

I also had this issue, as an alternative solution you can just move the config file to /etc/cloudflared/ manually.

deezest avatar Sep 28 '25 21:09 deezest