{"record":{"id":"6adde9d84ecef658","repo":"owasp-amass/amass","slug":"failed-to-set-permissions-to-0755-for-s-v","errorCode":null,"errorMessage":"failed to set permissions to 0755 for %s: %v","messagePattern":"failed to set permissions to 0755 for (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/tools/file.go","lineNumber":30,"sourceCode":"\t\"path/filepath\"\n\n\t\"github.com/owasp-amass/amass/v5/config\"\n\t\"github.com/owasp-amass/amass/v5/resources\"\n)\n\nfunc CreateOutputDirectory(dirpath string) error {\n\t// Prepare output file paths\n\tdir := config.OutputDirectory(dirpath)\n\tif dir == \"\" {\n\t\treturn errors.New(\"failed to obtain the path for the output directory\")\n\t}\n\t// If the directory does not yet exist, create it\n\tif err := os.MkdirAll(dir, 0755); err != nil {\n\t\treturn fmt.Errorf(\"mkdir failed for %s: %v\", dir, err)\n\t}\n\t// ensure that the permissions are set correctly\n\tif err := os.Chmod(dir, 0755); err != nil {\n\t\treturn fmt.Errorf(\"failed to set permissions to 0755 for %s: %v\", dir, err)\n\t}\n\treturn nil\n}\n\nfunc CreateDefaultConfigFiles(dirpath string) error {\n\tfor _, filename := range resources.DefaultFilesList {\n\t\tfilepath := filepath.Join(dirpath, filename)\n\t\tif _, err := os.Stat(filepath); !os.IsNotExist(err) {\n\t\t\t// If the file already exists, skip creating it\n\t\t\tcontinue\n\t\t}\n\n\t\tfile, err := resources.GetResourceFile(filename)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"failed to obtain the embedded file %s: %v\", filename, err)\n\t\t}\n\t\tdefer func() { _ = file.Close() }()\n","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/owasp-amass/amass/blob/79299dce87b0085db0f2f4ef3e9c52cccb49f514/internal/tools/file.go#L12-L48","documentation":"After creating the output directory, CreateOutputDirectory calls os.Chmod to force mode 0755. This error is returned when chmod fails, typically because the process does not own the directory (chmod requires ownership or appropriate privileges).","triggerScenarios":"The directory already existed and is owned by another user, the process runs as a non-root user against a directory owned by root, or the filesystem does not support chmod (some network mounts).","commonSituations":"Re-running the tool against a directory created earlier by a root-run container or a different service account; shared CI caches with root-owned artifacts; FAT/exFAT or Windows-mounted filesystems with no Unix permission model.","solutions":["Check ownership with ls -ld on the directory and chown it to the current user, or run the tool as the owning user","Delete the foreign-owned directory so the tool recreates it with correct ownership and mode","Skip a pre-existing directory whose permissions are already acceptable by creating it yourself with the intended mode first","On filesystems without chmod support, move the output directory to a native Unix filesystem"],"exampleFix":"// before\nsudo ./amass -dir /var/lib/amass   # dir owned by root, later chmod fails\n// after\nmkdir -p ~/amass-output && ./amass -dir ~/amass-output","handlingStrategy":"try-catch","validationCode":"if st, err := os.Stat(dir); err == nil {\n\tif st, _ := os.Stat(dir); st != nil && int(st.Mode().Perm()) != 0o755 {\n\t\t// only chmod when we own it\n\t\tif os.Getuid() != -1 && st.Uid != 0 { /* attempt fix */ }\n\t}\n}","typeGuard":"func ownedByCurrentUser(path string) bool {\n\tst, err := os.Stat(path)\n\treturn err == nil && st.Sys().(*syscall.Stat_t).Uid == uint32(os.Getuid())\n}","tryCatchPattern":"if err := tools.CreateOutputDirectory(dir); err != nil {\n\tif strings.Contains(err.Error(), \"set permissions\") {\n\t\tlog.Warn(\"could not chmod output dir; continuing with existing mode\")\n\t} else { return err }\n}","preventionTips":["Consistently run the tool as the same user so directories it creates stay owned by that user","Pre-create output directories with the desired mode/ownership before first run","Avoid mixing root and non-root invocations against the same directory (e.g. sudo then normal runs)","Use native Unix filesystems for output; avoid FAT/exFAT mounts that lack permission support"],"tags":["go","filesystem","permissions","chmod"],"backgroundTag":"permission-denied","analyzedSha":"79299dce87b0085db0f2f4ef3e9c52cccb49f514","analyzedAt":"2026-09-06T08:22:48.198Z","contentChangedAt":"2026-09-06T08:22:48.198Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}