hashicorp/terraform · error
Error chmodding script file to 0777 in remote machine
Error message
Error chmodding script file to 0777 in remote machine: %s
What it means
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.
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.
Example fix
// before
connection {
host = aws_instance.web.public_ip
user = "ubuntu"
private_key = file("~/.ssh/id_rsa")
}
// after
connection {
host = aws_instance.web.public_ip
user = "ubuntu"
private_key = file("~/.ssh/id_rsa")
timeout = "10m"
} Defensive patterns
Strategy: retry
Try / catch
// In Go, Start failures on the chmod are often transient channel issues;
// retry a few times, then surface the wrapped error:
if strings.Contains(err.Error(), "Error chmodding script file") {
if attempt < 3 { time.Sleep(backoff); continue }
return fmt.Errorf("could not chmod uploaded script: %w", err)
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: Flaky connection that drops right after upload; sshd MaxSessions reached; the host closed the channel; very slow link causing session setup to fail.
Related errors
- Error chmodding script file to 0777 in remote machine
- Error reading script
- Error creating temporary file for upload
- Error reading error message
- Failed to upload script
AI-assisted analysis of hashicorp/terraform@d32a084675 (2026-08-11).
Data as JSON: /api/errors/19814140c5aa34af.
Report an issue: GitHub.
Appendix: source
Thrown at internal/communicator/ssh/communicator.go:471
var script bytes.Buffer
if string(prefix) != "#!" && c.connInfo.TargetPlatform != TargetPlatformWindows {
script.WriteString(DefaultShebang)
}
script.ReadFrom(reader)
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 {View on GitHub (pinned to d32a084675)