How to Troubleshoot 'Permission Denied' Errors in Linux
Jul 26, 2025 am 02:57 AMTo fix "Permission denied" errors in Linux, first check file permissions with ls -l and adjust using chmod if needed; 1. Verify ownership and group with ls -l, then use sudo chown or sudo chgrp to change them; 2. Ensure your user is in the required group with groups and sudo usermod -aG; 3. Check for extended ACLs with getfacl and modify with setfacl if necessary; 4. Use lsattr to detect immutable flags and remove with sudo chattr -i; 5. Confirm the filesystem isn’t mounted read-only via mount or findmnt, and remount as read-write if safe; 6. Investigate SELinux with sestatus and ausearch, or AppArmor logs, and adjust policies instead of disabling; 7. Only use sudo when truly necessary, preferring proper ownership or permission fixes to avoid security risks, and always address the root cause rather than relying on elevated privileges.
"Permission denied" errors in Linux are common but can be frustrating if you're not sure where to start. These errors occur when a user or process tries to access a file, directory, or execute a command without the necessary permissions. Here’s how to troubleshoot and fix them effectively.

1. Check File or Directory Permissions
The first step is to inspect the current permissions using ls -l
:
ls -l /path/to/file
Example output:

-rw-r--r-- 1 alice users 1024 Jan 1 10:00 myfile.txt
- The first part (
-rw-r--r--
) shows permissions:- Owner (alice):
rw-
→ read and write - Group (users):
r--
→ read only - Others:
r--
→ read only
- Owner (alice):
- If you're trying to write or execute but don’t have permission, this is likely the issue.
? Fix: Use chmod
to adjust permissions (carefully):
# Give owner execute permission chmod u x script.sh # Allow group to write chmod g w /path/to/file # Be cautious with wide permissions like 777 chmod 777 /path/to/file # Not recommended for security
2. Verify Ownership and Group
Even with correct permissions, ownership matters. If you're not the owner or not in the right group, access will be denied.

Use ls -l
again to check owner and group:
-rw-r--r-- 1 bob admin 2048 Jan 1 11:00 config.conf
If you're logged in as alice
, you can't modify this file unless you have write permission for "others" — which you don’t.
? Fix: Change ownership with chown
:
# Change owner sudo chown alice config.conf # Change group sudo chgrp developers config.conf # Or both at once sudo chown alice:developers config.conf
Only use sudo
if you have admin rights and understand the implications.
3. Check If You’re in the Right Group
Some directories (like /var/www
, /dev
, or Docker sockets) require membership in specific groups.
? Check your current groups:
groups # or id
If you need access to Docker but aren’t in the docker
group:
sudo usermod -aG docker $USER
?? You’ll need to log out and back in (or restart your shell) for group changes to take effect.
4. Look for Special Permissions: Sticky Bit, ACLs, or Immutable Flags
Sometimes standard permissions aren’t the whole story.
a. Check for Access Control Lists (ACLs)
Some systems use extended ACLs:
getfacl /path/to/file
If ACLs are set, they can override regular permissions.
? To modify:
setfacl -m u:alice:rwx /path/to/file
b. Check for Immutable Files (chattr)
A file might be locked even for root:
lsattr /path/to/file
If you see i
(immutable), the file can't be modified.
? Remove the immutable flag:
sudo chattr -i /path/to/file
5. Filesystem Mounted as Read-Only
If you're getting "permission denied" on all write attempts in a directory, the filesystem might be mounted read-only.
? Check with:
mount | grep "your_partition" # or findmnt /path/to/dir
Look for ro
(read-only) instead of rw
(read-write).
? Remount as read-write (if safe):
sudo mount -o remount,rw /dev/sdX1 /mount/point
Common causes: disk errors, improper shutdown, or intentional setup.
6. SELinux or AppArmor Restrictions
Security modules like SELinux (common on RHEL/CentOS) or AppArmor (Ubuntu) can block access even if file permissions look correct.
? Check SELinux status:
sestatus
If enabled, check logs:
ausearch -m avc -ts recent # or dmesg | grep -i denied
? Temporarily test by disabling SELinux (not recommended long-term):
sudo setenforce 0
If the error goes away, adjust SELinux policies instead of leaving it off.
7. Running Commands with Proper Privileges
Sometimes you just need sudo
, but be careful:
sudo ./backup-script.sh
But avoid blindly using sudo
. Ask:
- Do I really need root?
- Can I fix ownership instead?
Using sudo
masks the real issue and can be a security risk.
Summary Checklist
When you see "Permission denied", go through these:
- ? Use
ls -l
to check permissions, owner, and group - ? Confirm you’re the owner or in the correct group
- ? Use
chmod
orchown
to fix access (with care) - ? Check for ACLs with
getfacl
- ? Look for immutable flags with
lsattr
- ? Verify the filesystem isn’t mounted read-only
- ? Consider SELinux/AppArmor if the system uses them
- ? Avoid overusing
sudo
— fix the root cause
Most permission issues come down to basic ownership or mode settings, but the deeper layers (like ACLs or security modules) can trip up even experienced users. Start simple, verify each layer, and you’ll resolve it quickly.
Basically, it’s not always about who you are — it’s about what the system lets you do.
The above is the detailed content of How to Troubleshoot 'Permission Denied' Errors in Linux. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

To tune MySQL into a Chinese interface, it can be implemented through MySQLWorkbench or command line tools. 1) In MySQLWorkbench, open "Preferences", select the "Appearance" tab, and then select "Chinese(Simplified)" in the "Language" drop-down menu, and restart. 2) When using command line tools, set the operating system locale variables, such as using "exportLANG=zh_CN.UTF-8" on Linux or macOS, and then run the mysql client.

Linux and Windows have their own advantages and disadvantages in CPU and memory usage: 1) Linux uses time slice-based scheduling algorithms to ensure fairness and efficiency; Windows uses priority scheduling, which may cause low-priority processes to wait. 2) Linux manages memory through paging and switching mechanisms to reduce fragmentation; Windows tends to pre-allocate and dynamic adjustment, and efficiency may fluctuate.

Linux's cost of ownership is usually lower than Windows. 1) Linux does not require license fees, saving a lot of costs, while Windows requires purchasing a license. 2) Linux has low hardware requirements and can extend the service life of the device. 3) The Linux community provides free support to reduce maintenance costs. 4) Linux is highly secure and reduces productivity losses. 5) The Linux learning curve is steep, but Windows is easier to use. The choice should be based on specific needs and budget.

LinuxoftenoutperformsWindowsinI/Operformanceduetoitscustomizablekernelandfilesystems,whileWindowsoffersmoreuniformperformanceacrosshardware.1)LinuxexcelswithcustomizableI/OschedulerslikeCFQandDeadline,enhancingperformanceinhigh-throughputapplications

The key to installing dual systems in Linux and Windows is partitioning and boot settings. 1. Preparation includes backing up data and compressing existing partitions to make space; 2. Use Ventoy or Rufus to make Linux boot USB disk, recommend Ubuntu; 3. Select "Coexist with other systems" or manually partition during installation (/at least 20GB, /home remaining space, swap optional); 4. Check the installation of third-party drivers to avoid hardware problems; 5. If you do not enter the Grub boot menu after installation, you can use boot-repair to repair the boot or adjust the BIOS startup sequence. As long as the steps are clear and the operation is done properly, the whole process is not complicated.

The key to enabling EPEL repository is to select the correct installation method according to the system version. First, confirm the system type and version, and use the command cat/etc/os-release to obtain information; second, enable EPEL through dnfinstallepel-release on CentOS/RockyLinux, and the 8 and 9 version commands are the same; third, you need to manually download the corresponding version of the .repo file and install it on RHEL; fourth, you can re-import the GPG key when encountering problems. Note that the old version may not be supported, and you can also consider enabling epel-next to obtain the test package. After completing the above steps, use dnfrepolist to verify that the EPEL repository is successfully added.

Newbie users should first clarify their usage requirements when choosing a Linux distribution. 1. Choose Ubuntu or LinuxMint for daily use; programming and development are suitable for Manjaro or Fedora; use Lubuntu and other lightweight systems for old devices; recommend CentOSStream or Debian to learn the underlying principles. 2. Stability is preferred for UbuntuLTS or Debian; you can choose Arch or Manjaro to pursue new features. 3. In terms of community support, Ubuntu and LinuxMint are rich in resources, and Arch documents are technically oriented. 4. In terms of installation difficulty, Ubuntu and LinuxMint are relatively simple, and Arch is suitable for those with basic needs. It is recommended to try it first and then decide.

Linux usually performs better in web server performance, mainly due to its advantages in kernel optimization, resource management and open source ecosystem. 1) After years of optimization of the Linux kernel, mechanisms such as epoll and kqueue make it more efficient in handling high concurrent requests. 2) Linux provides fine-grained resource management tools such as cgroups. 3) The open source community continuously optimizes Linux performance, and many high-performance web servers such as Nginx are developed on Linux. By contrast, Windows performs well when handling ASP.NET applications and provides better development tools and commercial support.
