How to Fix GitHub Action "Permission Denied" Error When Executing a File?

Why Does This Happen?

While running a file from a GitHub action, the "Permission denied" error, like the following, can happen when the file you are trying to execute does not have execution permissions:

/home/runner/work/_temp/ line 1: Permission denied
Error: Process completed with exit code 126.

An example workflow yml file that potentially causes the issue may look like the following:

name: CI

on: [push]

    runs-on: ubuntu-latest

      - name: Running PHPUnit Tests

How to Fix the Issue?

You can fix this issue by:

  • Adding execution permissions to the file, and;
  • Pushing the changes to the remote repository.

For example, on Linux or macOS, you can run the following command to set execution permission on the file:

$ chmod +x

On Windows, you can do the same using the following command:

$ git update-index --chmod=+x

Once you've done that, you should push your changes to the remote repository, for example, like so:

$ git add
$ git commit -m '...'
$ git push

Once you have completed these steps, you can retry running your GitHub action, and the "Permission denied" error should no longer occur.

This post was published by Daniyal Hamid. Daniyal currently works as the Head of Engineering in Germany and has 20+ years of experience in software engineering, design and marketing. Please show your love and support by sharing this post.