{"record":{"id":"19814140c5aa34af","repo":"hashicorp/terraform","slug":"error-chmodding-script-file-to-0777-in-remote-mach","errorCode":null,"errorMessage":"Error chmodding script file to 0777 in remote machine: %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":471,"sourceCode":"\tvar script bytes.Buffer\n\n\tif string(prefix) != \"#!\" && c.connInfo.TargetPlatform != TargetPlatformWindows {\n\t\tscript.WriteString(DefaultShebang)\n\t}\n\tscript.ReadFrom(reader)\n\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 {","sourceCodeStart":453,"sourceCodeEnd":489,"githubUrl":"https://github.com/hashicorp/terraform/blob/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/communicator/ssh/communicator.go#L453-L489","documentation":"Returned when c.Start() fails to launch the 'chmod 0777 <path>' command that makes an uploaded script executable on a Unix target. Start wraps the SSH session exec; failure here means the command could not be initiated (session/channels problem) rather than chmod itself returning non-zero (that is the sibling 787 error). It only runs on non-Windows target_platform.","triggerScenarios":"SSH session could not be opened for exec, the channel was exhausted/closed mid-upload, or the remote shell rejected the command before execution. Network hiccup after a successful upload but before the chmod exec.","commonSituations":"Flaky connection that drops right after upload; sshd MaxSessions reached; the host closed the channel; very slow link causing session setup to fail.","solutions":["Re-run apply; transient channel issues usually clear on retry.","Raise connection.timeout and lower parallelism if MaxSessions on the target is being hit.","Set script_path to a location the user can write and chmod, confirming permissions of the upload directory.","If persistent, check sshd config (MaxSessions, MaxStartups) and target disk/inode availability."],"exampleFix":"// before\nconnection {\n  host        = aws_instance.web.public_ip\n  user        = \"ubuntu\"\n  private_key = file(\"~/.ssh/id_rsa\")\n}\n\n// after\nconnection {\n  host        = aws_instance.web.public_ip\n  user        = \"ubuntu\"\n  private_key = file(\"~/.ssh/id_rsa\")\n  timeout     = \"10m\"\n}","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"// In Go, Start failures on the chmod are often transient channel issues;\n// retry a few times, then surface the wrapped error:\nif strings.Contains(err.Error(), \"Error chmodding script file\") {\n    if attempt < 3 { time.Sleep(backoff); continue }\n    return fmt.Errorf(\"could not chmod uploaded script: %w\", err)\n}","preventionTips":["Keep connection.timeout generous for flaky links.","Set script_path to a writable location for the SSH user.","Raise sshd MaxSessions if many parallel provisioners run."],"tags":["terraform","ssh","chmod","script","exec","upload","provisioner"],"backgroundTag":null,"analyzedSha":"d32a084675427f5ac3f7d2868578ef8b2c1dc525","analyzedAt":"2026-08-11T18:43:52.779Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}