'Permission denied' to run /tmp/script_nnnn.sh on linux 2023

I’m using HashiCorp Packer to create an image for AWS. The process works fine with Amazon Linux 2, but I encounter a “Permission denied” error when using Amazon Linux 2023.

It appears that there is the stricter permissions on the folder “/tmp” directory in Amazon Linux 2023 that prevents running shell scripts.

Is there a way that I can tell packer to use “/var/tmp” instead of “/tmp” to run the shell script?

I appreciate for any guidance and assistance to resolve this issue.

Here is the detail of the log that mentioned “Permission denied”

=============================
==> Connected to SSH!
==> Provisioning with shell script: /tmp/packer-shell179473623
==> bash: line 1: /tmp/script_4178.sh: Permission denied
==> Provisioning step had errors: Running the cleanup provisioner, if present…
==> Terminating the source AWS instance…
==> Cleaning up any extra volumes…
==> No volumes to clean up, skipping
==> Deleting temporary security group…
==> Deleting temporary keypair…
Build ‘ami.amazon-ebs.this’ errored after 1 minute 41 seconds: Script exited with non-zero exit status: 126.Allowed exit codes are: [0]

==> Wait completed after 1 minute 41 seconds

==> Some builds didn’t complete successfully and had errors:
→ Script exited with non-zero exit status: 126.Allowed exit codes are: [0]

==> Builds finished but no artifacts were created.

=============================

Thank you for your assistance.

3 Likes

Using external shell script file worked for me. Refer - Permission denied on shell script provisioner - #4 by tbugfinder

hello, OP. Did you find a solution for this? Running scripts by packer in AL2023 /tmp folder ?

I get the same when trying to build an AMI with packer and the teragrunt plugin:

packer {
  required_plugins {
    amazon-ami-management = {
      version = ">= 1.0.0"
      source  = "github.com/wata727/amazon-ami-management"
    }
  }
  required_version = ">= 1.7.0"
}

source "amazon-ebs" "ami_al2023_eks" {
...

The error:

 ==> amazon-ebs.vf_pcs_al2023_eks: Provisioning with shell script:
│ /var/folders/m9/tg704wtx5gv9fxx6ptt5c2kcj79ww0/T/packer-shell2757996708
│ ==> amazon-ebs.ami_al2023_eks: bash: line 1: /tmp/script_4174.sh:  Permission denied

It seems it is relateed to Amazon Linux 2023 /tmp folder being “nonexec”. Just created an EC2 with AL2023 and:

ssm-user@ip-10-20-9-18 ~]$ sudo su
[root@ip-10-20-9-18 ssm-user]# mount | grep /tmp
tmpfs on /tmp type tmpfs (rw,nosuid,nodev,***noexec***,relatime,seclabel,size=2097152k)
[root@ip-10-20-9-18 ssm-user]# date
Fri Aug  1 14:29:53 UTC 2025

ChatGpt says:
"In Amazon Linux 2023:. /tmp is mounted with noexec by default. "