hashicorp/terraform · error

Error chmodding script file to 0777 in remote machine %v: %s

Error message

Error chmodding script file to 0777 in remote machine %v: %s %s

What it means

Raised in Communicator.UploadScript when cmd.Wait() returns an error for the remote 'chmod 0777 <path>' command. Unlike error 781, the command was successfully started but exited with a non-zero status. The message includes the captured stdout and stderr from the remote chmod so the operator can see the remote shell's complaint.

Source

Thrown at internal/communicator/ssh/communicator.go:477

	if err := c.Upload(path, &script); err != nil {
		return err
	}
	if c.connInfo.TargetPlatform != TargetPlatformWindows {
		var stdout, stderr bytes.Buffer
		cmd := &remote.Cmd{
			Command: fmt.Sprintf("chmod 0777 %s", path),
			Stdout:  &stdout,
			Stderr:  &stderr,
		}
		if err := c.Start(cmd); err != nil {
			return fmt.Errorf(
				"Error chmodding script file to 0777 in remote "+
					"machine: %s", err)
		}

		if err := cmd.Wait(); err != nil {
			return fmt.Errorf(
				"Error chmodding script file to 0777 in remote "+
					"machine %v: %s %s", err, stdout.String(), stderr.String())
		}
	}
	return nil
}

// UploadDir implementation of communicator.Communicator interface
func (c *Communicator) UploadDir(dst string, src string) error {
	log.Printf("[DEBUG] Uploading dir '%s' to '%s'", src, dst)
	scpFunc := func(w io.Writer, r *bufio.Reader) error {
		uploadEntries := func() error {
			f, err := os.Open(src)
			if err != nil {
				return err
			}
			defer f.Close()

View on GitHub (pinned to c9def3e214)

Solutions

  1. Set script_path to a writable location the SSH user owns, such as /tmp/terraform_%RAND%.sh.
  2. Verify the SSH user has execute permission on the target directory and the filesystem is not mounted noexec or full.
  3. Check the stdout/stderr embedded in the error message for the exact remote shell error.
  4. Avoid spaces or shell-special characters in script_path.

Example fix

// before
connection {
  script_path = "/etc/deploy.sh"
}

// after
connection {
  script_path = "/tmp/terraform_%RAND%.sh"
}
Defensive patterns

Strategy: validation

Validate before calling

// Validate script_path is writable before provisioning
func validateScriptPath(path string, targetPlatform string) error {
    if targetPlatform != "windows" {
        dir := filepath.Dir(path)
        if !strings.HasPrefix(dir, "/tmp") && !strings.HasPrefix(dir, "/var/tmp") {
            log.Printf("[WARN] script_path %s may not be writable by the SSH user", path)
        }
    }
    return nil
}

Prevention

When it happens

Trigger: The chmod command started but failed on the remote host: the uploaded script path does not exist on the remote, the SSH user lacks write/execute permission on the target directory, or the remote filesystem is read-only.

Common situations: Script path points to a directory the SSH user cannot write to (e.g. /etc/), the /tmp partition is mounted noexec or is full, or the script_path template expanded to a path with spaces/special characters that the remote shell misinterpreted.

Related errors


AI-assisted analysis of hashicorp/terraform@c9def3e214 (2026-08-07). Data as JSON: /api/errors/4bfd84c9380f9027. Report an issue: GitHub.