{"record":{"id":"46bf3c4e4c854f14","repo":"ipfs/kubo","slug":"s-is-not-writeable-by-the-current-user","errorCode":null,"errorMessage":"%s is not writeable by the current user","messagePattern":"(.+?) is not writeable by the current user","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/ipfs/kubo/init.go","lineNumber":186,"sourceCode":"\n\tif !empty {\n\t\tif err := addDefaultAssets(out, repoRoot); err != nil {\n\t\t\treturn err\n\t\t}\n\t}\n\n\treturn pinEmptyDir(repoRoot)\n}\n\nfunc checkWritable(dir string) error {\n\t_, err := os.Stat(dir)\n\tif err == nil {\n\t\t// dir exists, make sure we can write to it\n\t\ttestfile := filepath.Join(dir, \"test\")\n\t\tfi, err := os.Create(testfile)\n\t\tif err != nil {\n\t\t\tif os.IsPermission(err) {\n\t\t\t\treturn fmt.Errorf(\"%s is not writeable by the current user\", dir)\n\t\t\t}\n\t\t\treturn fmt.Errorf(\"unexpected error while checking writeablility of repo root: %s\", err)\n\t\t}\n\t\tfi.Close()\n\t\treturn os.Remove(testfile)\n\t}\n\n\tif os.IsNotExist(err) {\n\t\t// dir doesn't exist, check that we can create it\n\t\treturn os.Mkdir(dir, 0o775)\n\t}\n\n\tif os.IsPermission(err) {\n\t\treturn fmt.Errorf(\"cannot write to %s, incorrect permissions\", err)\n\t}\n\n\treturn err\n}","sourceCodeStart":168,"sourceCodeEnd":204,"githubUrl":"https://github.com/ipfs/kubo/blob/329838acdfafae224582930457efe80aa217afc0/cmd/ipfs/kubo/init.go#L168-L204","documentation":"Thrown by checkWritable when the IPFS_REPO_PATH (or target repo dir) exists but the current OS user cannot create files inside it: the probe file `<dir>/test` could not be created and the OS reported a permission error. Init aborts before creating any repo data. The message names the directory so you can inspect its ownership and mode.","triggerScenarios":"Calling `ipfs init` with IPFS_PATH or the default ~/.ipfs pointing at an existing directory where os.Create(\"<dir>/test\") fails with EACCES/EPERM (e.g. dir owned by root or another user, or read-only mount).","commonSituations":"Running ipfs under systemd/Docker as a user different from the repo owner; IPFS_PATH pointing into /root from an unprivileged shell; a volume mounted read-only; a previous run with sudo created ~/.ipfs owned by root.","solutions":["Check ownership and permissions with `ls -ld <dir>` and fix them: `sudo chown -R $(id -u):$(id -g) <dir>` or `chmod u+w <dir>`.","If the dir was created by a previous sudo run, remove it (`sudo rm -rf <dir>`) and re-run `ipfs init` as your normal user.","Point IPFS_PATH at a directory you can write to, e.g. `export IPFS_PATH=$(mktemp -d)`.","If the mount is read-only, remount read-write or choose a different location."],"exampleFix":"// before\nsudo ipfs init   # creates repo owned by root\n// after\nrm -rf ~/.ipfs   # remove root-owned repo, then run as the regular user\nipfs init","handlingStrategy":"validation","validationCode":"dir := os.Getenv(\"IPFS_PATH\")\nif dir == \"\" {\n\tdir = \"~/.ipfs\"\n}\nfi, err := os.Stat(dir)\nif err == nil && fi.IsDir() {\n\tprobe, perr := os.Create(filepath.Join(dir, \".write-test\"))\n\tif perr != nil {\n\t\tlog.Fatalf(\"repo dir %s not writable: %v\", dir, perr)\n\t}\n\tprobe.Close()\n\tos.Remove(filepath.Join(dir, \".write-test\"))\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never run `ipfs init` with sudo; fix permissions instead","After switching users or containers, `chown -R` the repo to the running user","Set IPFS_PATH explicitly in scripts to a path you control"],"tags":["filesystem","permissions","init"],"backgroundTag":"directory-not-writable","analyzedSha":"329838acdfafae224582930457efe80aa217afc0","analyzedAt":"2026-09-03T18:30:52.135Z","contentChangedAt":"2026-09-03T18:30:52.135Z","schemaVersion":2},"datasetVersion":"2026-09-11T00:17:11.886Z"}