hashicorp/terraform · error
Error chmodding script file to 0777 in remote machine: %s
Error message
Error chmodding script file to 0777 in remote machine: %s
What it means
Raised in Communicator.UploadScript when c.Start(cmd) fails for the remote 'chmod 0777 <path>' command that runs after a successful script upload on unix targets. Start opens a new SSH session and begins the command; a failure here means the session could not be established or the command could not be launched (e.g. connection dropped, session allocation failed, or PTY request failed).
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 c9def3e214)
Solutions
- Check that the SSH connection is stable and not timing out between upload and chmod (increase connection timeout in the provisioner connection block).
- Verify the remote sshd MaxSessions and MaxStartups limits are not exhausted.
- Ensure the script_path does not contain characters that break the remote shell.
- Retry the provisioner run; transient connection drops during long uploads are common.
Example fix
// before
connection {
host = var.host
timeout = "30s"
}
// after
connection {
host = var.host
timeout = "10m"
} Defensive patterns
Strategy: retry
Try / catch
// Wrap UploadScript with retry on session-start failure
func uploadScriptWithRetry(comm *Communicator, path string, r io.Reader, maxRetries int) error {
for i := 0; i < maxRetries; i++ {
err := comm.UploadScript(path, r)
if err == nil {
return nil
}
if strings.Contains(err.Error(), "chmodding script file to 0777") {
time.Sleep(time.Duration(i+1) * 2 * time.Second)
continue
}
return err
}
return errors.New("max retries exceeded for script upload")
} Prevention
- Set a generous connection timeout in the connection block to survive transient drops.
- Keep scripts small to minimize the upload window before chmod runs.
- Ensure the remote sshd MaxSessions is high enough for concurrent sessions.
When it happens
Trigger: After the script file is uploaded via SCP, the communicator starts a remote chmod command. This error fires if newSession() fails (client disconnected or nil), if session.RequestPty() fails, or if session.Start() returns an error for the chmod invocation.
Common situations: The SSH connection dropped between the SCP upload and the chmod call (e.g. server-side idle timeout, network blip), the remote sshd has a low MaxSessions limit and the session cannot be allocated, or the script path contains characters that break the remote shell.
Related errors
- Error reading script: %s
- Error chmodding script file to 0777 in remote machine %v: %s
- Upload failed: %v
- Failed to upload script: %v
- Error starting script: %v
AI-assisted analysis of hashicorp/terraform@c9def3e214 (2026-08-07).
Data as JSON: /api/errors/19814140c5aa34af.
Report an issue: GitHub.