owasp-amass/amass · error

failed to set permissions to 0755 for %s: %v

Error message

failed to set permissions to 0755 for %s: %v

What it means

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).

Source

Thrown at internal/tools/file.go:30

	"path/filepath"

	"github.com/owasp-amass/amass/v5/config"
	"github.com/owasp-amass/amass/v5/resources"
)

func CreateOutputDirectory(dirpath string) error {
	// Prepare output file paths
	dir := config.OutputDirectory(dirpath)
	if dir == "" {
		return errors.New("failed to obtain the path for the output directory")
	}
	// If the directory does not yet exist, create it
	if err := os.MkdirAll(dir, 0755); err != nil {
		return fmt.Errorf("mkdir failed for %s: %v", dir, err)
	}
	// ensure that the permissions are set correctly
	if err := os.Chmod(dir, 0755); err != nil {
		return fmt.Errorf("failed to set permissions to 0755 for %s: %v", dir, err)
	}
	return nil
}

func CreateDefaultConfigFiles(dirpath string) error {
	for _, filename := range resources.DefaultFilesList {
		filepath := filepath.Join(dirpath, filename)
		if _, err := os.Stat(filepath); !os.IsNotExist(err) {
			// If the file already exists, skip creating it
			continue
		}

		file, err := resources.GetResourceFile(filename)
		if err != nil {
			return fmt.Errorf("failed to obtain the embedded file %s: %v", filename, err)
		}
		defer func() { _ = file.Close() }()

View on GitHub (pinned to 79299dce87)

Solutions

  1. Check ownership with ls -ld on the directory and chown it to the current user, or run the tool as the owning user
  2. Delete the foreign-owned directory so the tool recreates it with correct ownership and mode
  3. Skip a pre-existing directory whose permissions are already acceptable by creating it yourself with the intended mode first
  4. On filesystems without chmod support, move the output directory to a native Unix filesystem

Example fix

// before
sudo ./amass -dir /var/lib/amass   # dir owned by root, later chmod fails
// after
mkdir -p ~/amass-output && ./amass -dir ~/amass-output
Defensive patterns

Strategy: try-catch

Validate before calling

if st, err := os.Stat(dir); err == nil {
	if st, _ := os.Stat(dir); st != nil && int(st.Mode().Perm()) != 0o755 {
		// only chmod when we own it
		if os.Getuid() != -1 && st.Uid != 0 { /* attempt fix */ }
	}
}

Type guard

func ownedByCurrentUser(path string) bool {
	st, err := os.Stat(path)
	return err == nil && st.Sys().(*syscall.Stat_t).Uid == uint32(os.Getuid())
}

Try / catch

if err := tools.CreateOutputDirectory(dir); err != nil {
	if strings.Contains(err.Error(), "set permissions") {
		log.Warn("could not chmod output dir; continuing with existing mode")
	} else { return err }
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Understand the failure class

Background: Permission denied / not authorized / 403 Forbidden: access-control rejections when the caller lacks the required role, grant, or ownership — this error's family across 18 libraries.

Related errors


AI-assisted analysis of owasp-amass/amass@79299dce87 (2026-09-06). Data as JSON: /api/errors/6adde9d84ecef658. Report an issue: GitHub.