{"record":{"id":"4bfd84c9380f9027","repo":"hashicorp/terraform","slug":"error-chmodding-script-file-to-0777-in-remote-mach-4bfd84","errorCode":null,"errorMessage":"Error chmodding script file to 0777 in remote machine %v: %s %s","messagePattern":"Error chmodding script file to 0777 in remote machine (.+?): (.+?) (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/communicator/ssh/communicator.go","lineNumber":477,"sourceCode":"\n\tif err := c.Upload(path, &script); err != nil {\n\t\treturn err\n\t}\n\tif c.connInfo.TargetPlatform != TargetPlatformWindows {\n\t\tvar stdout, stderr bytes.Buffer\n\t\tcmd := &remote.Cmd{\n\t\t\tCommand: fmt.Sprintf(\"chmod 0777 %s\", path),\n\t\t\tStdout:  &stdout,\n\t\t\tStderr:  &stderr,\n\t\t}\n\t\tif err := c.Start(cmd); err != nil {\n\t\t\treturn fmt.Errorf(\n\t\t\t\t\"Error chmodding script file to 0777 in remote \"+\n\t\t\t\t\t\"machine: %s\", err)\n\t\t}\n\n\t\tif err := cmd.Wait(); err != nil {\n\t\t\treturn fmt.Errorf(\n\t\t\t\t\"Error chmodding script file to 0777 in remote \"+\n\t\t\t\t\t\"machine %v: %s %s\", err, stdout.String(), stderr.String())\n\t\t}\n\t}\n\treturn nil\n}\n\n// UploadDir implementation of communicator.Communicator interface\nfunc (c *Communicator) UploadDir(dst string, src string) error {\n\tlog.Printf(\"[DEBUG] Uploading dir '%s' to '%s'\", src, dst)\n\tscpFunc := func(w io.Writer, r *bufio.Reader) error {\n\t\tuploadEntries := func() error {\n\t\t\tf, err := os.Open(src)\n\t\t\tif err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t\tdefer f.Close()\n","sourceCodeStart":459,"sourceCodeEnd":495,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/communicator/ssh/communicator.go#L459-L495","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Set script_path to a writable location the SSH user owns, such as /tmp/terraform_%RAND%.sh.","Verify the SSH user has execute permission on the target directory and the filesystem is not mounted noexec or full.","Check the stdout/stderr embedded in the error message for the exact remote shell error.","Avoid spaces or shell-special characters in script_path."],"exampleFix":"// before\nconnection {\n  script_path = \"/etc/deploy.sh\"\n}\n\n// after\nconnection {\n  script_path = \"/tmp/terraform_%RAND%.sh\"\n}","handlingStrategy":"validation","validationCode":"// Validate script_path is writable before provisioning\nfunc validateScriptPath(path string, targetPlatform string) error {\n    if targetPlatform != \"windows\" {\n        dir := filepath.Dir(path)\n        if !strings.HasPrefix(dir, \"/tmp\") && !strings.HasPrefix(dir, \"/var/tmp\") {\n            log.Printf(\"[WARN] script_path %s may not be writable by the SSH user\", path)\n        }\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use the default script_path (/tmp/terraform_%RAND%.sh) which is writable on most unix systems.","Avoid special characters and spaces in script_path.","Confirm the SSH user has write and execute permissions on the script_path directory."],"tags":["ssh","chmod","permissions","script-path","terraform"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T21:17:07.882Z"}