{"record":{"id":"80b31dc2b58c78df","repo":"hashicorp/packer","slug":"error-chmodding-script-file-to-0755-in-remote-mach","errorCode":null,"errorMessage":"Error chmodding script file to 0755 in remote machine: %s","messagePattern":"Error chmodding script file to 0755 in remote machine: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"provisioner/shell/provisioner.go","lineNumber":342,"sourceCode":"\t\terr = retry.Config{StartTimeout: p.config.StartRetryTimeout}.Run(ctx, func(ctx context.Context) error {\n\t\t\tif _, err := f.Seek(0, 0); err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\n\t\t\tvar r io.Reader = f\n\t\t\tif !p.config.Binary {\n\t\t\t\tr = &UnixReader{Reader: r}\n\t\t\t}\n\n\t\t\tif err := comm.Upload(p.config.RemotePath, r, nil); err != nil {\n\t\t\t\treturn fmt.Errorf(\"Error uploading script: %s\", err)\n\t\t\t}\n\n\t\t\tcmd = &packersdk.RemoteCmd{\n\t\t\t\tCommand: fmt.Sprintf(\"chmod 0755 %s\", p.config.RemotePath),\n\t\t\t}\n\t\t\tif err := comm.Start(ctx, cmd); err != nil {\n\t\t\t\treturn fmt.Errorf(\n\t\t\t\t\t\"Error chmodding script file to 0755 in remote \"+\n\t\t\t\t\t\t\"machine: %s\", err)\n\t\t\t}\n\t\t\tcmd.Wait()\n\n\t\t\tcmd = &packersdk.RemoteCmd{Command: command}\n\t\t\treturn cmd.RunWithUi(ctx, comm, ui)\n\t\t})\n\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\n\t\t// If the exit code indicates a remote disconnect, fail unless\n\t\t// we were expecting it.\n\t\tif cmd.ExitStatus() == packersdk.CmdDisconnect {\n\t\t\tif !p.config.ExpectDisconnect {\n\t\t\t\treturn fmt.Errorf(\"Script disconnected unexpectedly. \" +","sourceCodeStart":324,"sourceCodeEnd":360,"githubUrl":"https://github.com/hashicorp/packer/blob/eb36e3c3e48a036f3e8cc94087636ee72e1303c9/provisioner/shell/provisioner.go#L324-L360","documentation":"After uploading the script, the provisioner runs `chmod 0755 <RemotePath>` on the remote host via comm.Start. If the communicator cannot start that command (connection lost, shell unavailable, command channel error), the retryable function returns this wrapped error. Note this only fires on failure to START the chmod command, not on a non-zero chmod exit status, which is ignored.","triggerScenarios":"comm.Start(ctx, cmd) failing while running the chmod command inside the upload/retry block — typically a dropped SSH/WinRM session, or a communicator that cannot spawn a shell at that moment (e.g. machine mid-reboot).","commonSituations":"The instance restarted between upload and chmod so the SSH session died; sshd hit MaxSessions/connection limits; WinRM shell quota exhausted; transient network drops on long-running builds.","solutions":["Increase start_retry_timeout so the built-in retry can ride out transient disconnects","Verify the remote host's SSH/WinRM service is stable (no rebooting mid-provision)","Check sshd MaxSessions/MaxStartups limits if parallel provisioners are used","Re-run the build after confirming the machine is not restarting during provisioning"],"exampleFix":"// before\nprovisioner \"shell\" {\n  start_retry_timeout = \"5m\"\n}\n// after\nprovisioner \"shell\" {\n  start_retry_timeout = \"15m\"\n}","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"err = retry.Config{StartTimeout: p.config.StartRetryTimeout}.Run(ctx, func(ctx context.Context) error {\n    // upload, then:\n    if err := comm.Start(ctx, chmodCmd); err != nil {\n        return fmt.Errorf(\"Error chmodding script file to 0755 in remote machine: %s\", err)\n    }\n    return nil\n})","preventionTips":["Keep start_retry_timeout generous enough to absorb transient disconnects","Ensure no other step reboots the machine between upload and execution","Check sshd MaxSessions/MaxStartups when running parallel provisioners","Confirm the guest's shell service (sshd/WinRM) is stable during provisioning"],"tags":["provisioner","shell","chmod","communicator","ssh"],"backgroundTag":"remote-command-execution-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"}