You may see a Permission denied error when you try to execute a Python, Shell, or Bash scripts on Linux distributions, Unix, or macOS Terminals.
Example: zsh shell on macOS
% ./script.sh zsh: permission denied: ./script.sh
Example: Sh Shell
# ./script.sh bash: ./script.sh: Permission denied
Example: Bash Shell
$ ./script.sh sh: ./script.sh: Permission denied
Now let's take a look at file permissions using ls command on the script.sh file.
% ls -ls script.sh 0 -rw-r--r-- 1 c2ctechtv staff 0 Jul 16 02:49 script.sh
Let's try to understand what permissions we have on the file using a table.
As you can see not of the users have the execute permission enabled, hence the erorr.
Let's make use of chmod +x on the file.
% chmod +x script.sh % ls -l chmod+x script.sh -rwxr-xr-x 1 c2ctechtv staff 0 Jul 16 02:49 script.sh
Conclusion: As you can see after executing chmod +x on a file, all the users/groups/others get the rights to execute the file.
Facing issues? Have Questions? Post them here! I am happy to answer!
- Command to know the Available Memory on Linux System
- How to install curl on Alpine Linux
- How to backup a file in Linux/Unix
- Install Java Runtime Environment (Oracle or open JRE) on Ubuntu
- What is the Default Admin user and Password for Jenkins
- How to tar.gz a directory or folder Command
- Copy entire directory using Terminal Command [Linux, Mac, Bash]
- Fix: bash: ipconfig: command not found on Linux
- Command to check Last Login or Reboot History of Users and TTYs
- Linux: Create a New User and Password and Login Example
- ls command to list only directories
- bash: cls: command not found
- How to exit from nano command
- Installing and using unzip Command to unzip a zip file using Terminal
- What does apt-get update command does?
- ls command: sort files by name alphabetically A-Z or Z-A [Linux/Unix/macOS/Bash]
- How to remove or uninstall Java from Ubuntu using apt-get
- scp: ssh: connect to host xxxx port 22: Connection refused Error
- Sort ls command by last modified date and time
- Create Nested Directories using mkdir Command
- How to Exit a File in Terminal (Bash/Zsh)
- Command to know the installed Debian version?
- How to connect to SSH port other than default 22
- How to save a file in Nano Editor and Exit
- Install OpenSSL on Linux/Ubuntu
- How to Update Roblox on Mac - MacOS
- 21 Essential Mac Terminal Shortcuts for Devs and DevOps to Boost Productivity - MacOS
- Where are Notepad++ macros stored? - NotepadPlusPlus
- [Fix] MySQL Docker ERROR 1045 (28000): Access denied for user root@localhost (using password: YES/NO) - MySQL
- Change Mac Terminal Font Size using Command - MacOS
- Android Studio : Connection Error : Failed to download patch file - Android-Studio
- Google Search Hot Trends Screensaver for Mac OS X - MacOS
- Setting Up VS Code with Java JDK 21 - Java-JDK-21