{"record":{"id":"ee96d6b2ec5c892a","repo":"hashicorp/packer","slug":"error-chmodding-script-file-to-0600-in-remote-mach","errorCode":null,"errorMessage":"Error chmodding script file to 0600 in remote machine: %s","messagePattern":"Error chmodding script file to 0600 in remote machine: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"provisioner/shell/provisioner.go","lineNumber":282,"sourceCode":"\t\t\t\treturn err\n\t\t\t}\n\n\t\t\tvar r io.Reader = tf\n\t\t\tif !p.config.Binary {\n\t\t\t\tr = &UnixReader{Reader: r}\n\t\t\t}\n\t\t\tremoteVFName := fmt.Sprintf(\"%s/%s\", p.config.RemoteFolder,\n\t\t\t\tfmt.Sprintf(\"varfile_%d.sh\", rand.Intn(9999)))\n\t\t\tif err := comm.Upload(remoteVFName, r, nil); err != nil {\n\t\t\t\treturn fmt.Errorf(\"Error uploading envVarFile: %s\", err)\n\t\t\t}\n\t\t\ttf.Close()\n\n\t\t\tcmd = &packersdk.RemoteCmd{\n\t\t\t\tCommand: fmt.Sprintf(\"chmod 0600 %s\", remoteVFName),\n\t\t\t}\n\t\t\tif err := comm.Start(ctx, cmd); err != nil {\n\t\t\t\treturn fmt.Errorf(\"Error chmodding script file to 0600 in remote machine: %s\", err)\n\t\t\t}\n\t\t\tcmd.Wait()\n\t\t\tp.config.envVarFile = remoteVFName\n\t\t\treturn nil\n\t\t})\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t}\n\n\t// Create environment variables to set before executing the command\n\tflattenedEnvVars := p.createFlattenedEnvVars()\n\n\tfor _, path := range scripts {\n\t\tui.Say(fmt.Sprintf(\"Provisioning with shell script: %s\", path))\n\n\t\tlog.Printf(\"Opening %s for reading\", path)\n\t\tf, err := os.Open(path)","sourceCodeStart":264,"sourceCodeEnd":300,"githubUrl":"https://github.com/hashicorp/packer/blob/eb36e3c3e48a036f3e8cc94087636ee72e1303c9/provisioner/shell/provisioner.go#L264-L300","documentation":"Right after uploading the env-var file, Packer runs `chmod 0600 <remoteVFName>` on the remote machine through the communicator (provisioner/shell/provisioner.go:282). This error wraps a failure to start that remote command — i.e., the communicator session could not be established or the command could not be launched. Note cmd.Wait() is called but the chmod exit status is not checked; only the Start failure is reported here.","triggerScenarios":"comm.Start(ctx, cmd) fails immediately after a successful upload: SSH connection dropped between upload and chmod, session multiplexing exhausted (MaxSessions), or the shell on the remote host cannot be spawned.","commonSituations":"OpenSSH MaxSessions limit reached with connection pooling; remote machine rebooted mid-provision by a restart provisioner; sshd rate limiting or fail2ban blocking repeated connections; flaky cloud networking.","solutions":["Raise ssh MaxSessions/handshake limits (ssh_keep_alive_interval, ssh_handshake_attempts) or disable connection pooling.","Increase start_retry_timeout so retries ride out reconnection windows.","Ensure no restart provisioner reboots the machine without waiting for SSH to come back.","Check the remote host's sshd logs (auth.log) for session refusal causes such as fail2ban.","Run with PACKER_LOG=1 to capture the exact communicator Start error."],"exampleFix":"// before\nsource \"amazon-ebs\" \"ex\" {\n  ssh_handshake_attempts = 10\n}\n// after\nsource \"amazon-ebs\" \"ex\" {\n  ssh_handshake_attempts     = 30\n  ssh_keep_alive_interval    = \"30s\"\n}","handlingStrategy":"retry","validationCode":"// confirm sshd tolerates the session load before building\nssh -o ConnectTimeout=5 \"$SSH_USER@$SSH_HOST\" 'echo remote-ok' || { echo \"ssh session start failed\"; exit 1; }","typeGuard":null,"tryCatchPattern":"// communicate-level: treat Start failures as transient and retry with backoff\nerr := retry.Config{StartTimeout: 10 * time.Minute}.Run(ctx, func(ctx context.Context) error {\n    if err := p.Provision(ctx, ui, comm, data); err != nil {\n        if strings.Contains(err.Error(), \"chmodding script file\") {\n            return err // retried by retry.Run\n        }\n        return retry.Fatal(err)\n    }\n    return nil\n})","preventionTips":["Increase ssh_handshake_attempts and ssh_keep_alive_interval in the source config.","Check remote sshd MaxSessions and fail2ban rules when using connection pooling.","Give restart provisioners time to restore connectivity before shell steps.","Watch the chmod exit status too — Start success does not guarantee chmod succeeded."],"tags":["communicator","ssh","remote-command","chmod"],"backgroundTag":"remote-command-start-failed","analyzedSha":"eb36e3c3e48a036f3e8cc94087636ee72e1303c9","analyzedAt":"2026-09-05T13:20:43.127Z","contentChangedAt":"2026-09-05T13:20:43.127Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}