bash: ./script.sh: Permission denied
PermissionError: [Errno 13] Permission denied
EACCES: permission denied
Your user account doesn’t have permission to read, write, or execute the file or directory.
Fix 1: Make a Script Executable
# ❌ Script isn't executable
./script.sh # Permission denied
# ✅ Add execute permission
chmod +x script.sh
./script.sh
Fix 2: Wrong File Ownership
# Check who owns the file
ls -la file.txt
# Change ownership to your user
sudo chown $USER:$USER file.txt
# Or change ownership recursively
sudo chown -R $USER:$USER /path/to/directory
Fix 3: Need sudo
# ❌ Writing to a system directory
echo "data" > /etc/myconfig # Permission denied
# ✅ Use sudo
echo "data" | sudo tee /etc/myconfig
Don’t use sudo for everything — only when you actually need root access.
Fix 4: SSH Key Permissions
# ❌ SSH key has wrong permissions
ssh user@host # Permission denied (publickey)
# ✅ Fix key permissions
chmod 600 ~/.ssh/id_rsa
chmod 644 ~/.ssh/id_rsa.pub
chmod 700 ~/.ssh
Fix 5: npm Global Install
# ❌ Installing global packages without permission
npm install -g typescript # EACCES
# ✅ Fix npm permissions
mkdir ~/.npm-global
npm config set prefix '~/.npm-global'
echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.bashrc
source ~/.bashrc
Fix 6: Docker Permission Denied
# ❌ Can't run docker commands
docker ps # Permission denied
# ✅ Add your user to the docker group
sudo usermod -aG docker $USER
# Log out and back in
Quick Reference
# Read/write/execute for owner only
chmod 700 file
# Read/write for owner, read for others
chmod 644 file
# Check current permissions
ls -la file
# Check who you are
whoami