{"record":{"id":"886cb177c766e65a","repo":"cloudflare/cloudflared","slug":"failed-to-copy-s-to-s-w","errorCode":null,"errorMessage":"failed to copy %s to %s: %w","messagePattern":"failed to copy (.+?) to (.+?): %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/cloudflared/linux_service.go","lineNumber":340,"sourceCode":"\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\t// can't use context because this command doesn't define \"credentials-file\" flag\n\tconfigPresent := func(s string) bool {\n\t\tval, err := src.String(s)\n\t\treturn err == nil && val != \"\"\n\t}\n\tif src.TunnelID == \"\" || !configPresent(tunnel.CredFileFlag) {\n\t\treturn nil, fmt.Errorf(\"configuration file %s must contain entries for the tunnel to run and its associated credentials (tunnel: TUNNEL-UUID, credentials-file: CREDENTIALS-FILE)\", src.Source())\n\t}\n\tif src.Source() != serviceConfigPath {\n\t\tif exists, err := config.FileExists(serviceConfigPath); err != nil || exists {\n\t\t\treturn nil, fmt.Errorf(\"possible conflicting configuration in %[1]s and %[2]s. Either remove %[2]s or run `cloudflared --config %[2]s service install`\", src.Source(), serviceConfigPath)\n\t\t}\n\n\t\tif err := copyFile(src.Source(), serviceConfigPath); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"failed to copy %s to %s: %w\", src.Source(), serviceConfigPath, err)\n\t\t}\n\t}\n\n\treturn []string{\n\t\t\"--config\", \"/etc/cloudflared/config.yml\", \"tunnel\", \"run\",\n\t}, nil\n}\n\nfunc installSystemd(templateArgs *ServiceTemplateArgs, autoUpdate bool, log *zerolog.Logger) error {\n\tvar systemdTemplates []ServiceTemplate\n\tif autoUpdate {\n\t\tsystemdTemplates = []ServiceTemplate{\n\t\t\tsystemdAllTemplates[cloudflaredService],\n\t\t\tsystemdAllTemplates[cloudflaredUpdateService],\n\t\t\tsystemdAllTemplates[cloudflaredUpdateTimer],\n\t\t}\n\t} else {\n\t\tsystemdTemplates = []ServiceTemplate{","sourceCodeStart":322,"sourceCodeEnd":358,"githubUrl":"https://github.com/cloudflare/cloudflared/blob/2253eeeb25a44a713a4b60b8ba1e1b3f377d1a0f/cmd/cloudflared/linux_service.go#L322-L358","documentation":"Wraps a failure from copyFile when buildArgsForConfig copies the user's config to the canonical service path /etc/cloudflared/config.yml during service installation. If the file cannot be read or written (permissions, missing source, disk full), install aborts with the source and destination paths in the message.","triggerScenarios":"`cloudflared service install` with a --config file whose source path differs from serviceConfigPath, where copyFile(src.Source(), \"/etc/cloudflared/config.yml\") fails — unwritable /etc/cloudflared directory (not running as root), unreadable source file, or I/O error.","commonSituations":"Running service install without sudo so the /etc/cloudflared directory is not writable; config file in a home directory with restrictive permissions; read-only or full filesystem; SELinux/AppArmor blocking writes to /etc.","solutions":["Run the install with root privileges: `sudo cloudflared --config <config> service install`.","Ensure the source config file is readable by root (check permissions/ownership with ls -l).","Verify /etc/cloudflared exists and is writable (sudo mkdir -p /etc/cloudflared).","Check disk space and any mandatory access control (SELinux) denials in audit logs.","As a workaround, manually copy the config: `sudo cp <config> /etc/cloudflared/config.yml` then install using that path."],"exampleFix":"# before\n$ cloudflared --config ~/myconfig.yml service install\n# ERROR: failed to copy /home/user/myconfig.yml to /etc/cloudflared/config.yml\n\n# after\n$ sudo cloudflared --config ~/myconfig.yml service install","handlingStrategy":"validation","validationCode":"// Go: preflight write-access check before service install\nif os.Geteuid() != 0 {\n    return fmt.Errorf(\"service install requires root; re-run with sudo\")\n}\nif err := os.MkdirAll(\"/etc/cloudflared\", 0755); err != nil {\n    return fmt.Errorf(\"cannot create /etc/cloudflared: %w\", err)\n}\nf, err := os.OpenFile(\"/etc/cloudflared/.write-test\", os.O_CREATE|os.O_WRONLY, 0644)\nif err != nil {\n    return fmt.Errorf(\"/etc/cloudflared not writable: %w\", err)\n}\nf.Close()\nos.Remove(\"/etc/cloudflared/.write-test\")","typeGuard":null,"tryCatchPattern":"// Go\nout, err := exec.Command(\"cloudflared\", \"--config\", cfg, \"service\", \"install\").CombinedOutput()\nif err != nil && strings.Contains(string(out), \"failed to copy\") {\n    // fall back to manual copy: sudo cp cfg /etc/cloudflared/config.yml then reinstall\n}","preventionTips":["Always run `cloudflared service install` with sudo/root","Pre-create /etc/cloudflared with correct ownership (root:root, 0755)","Ensure the source config file has read permissions for root","Check disk space and SELinux/AppArmor denials on hosts where installs are automated"],"tags":["cli","filesystem","service-install","permissions"],"backgroundTag":"file-write-failed","analyzedSha":"2253eeeb25a44a713a4b60b8ba1e1b3f377d1a0f","analyzedAt":"2026-09-06T04:14:33.757Z","contentChangedAt":"2026-09-06T04:14:33.757Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}