Linux Permissions and Ownership Explained Without Jargon
Linux permissions sound complicated mainly because they are usually explained using strings such as:
-rwxr-x---
and numbers such as:
750
before anyone explains what they actually mean.
At their core, Linux permissions answer four questions:
Who owns this file or folder?
Which group is associated with it?
What can the owner do?
What can the group and everyone else do?
Once those ideas make sense, commands such as:
chmod
chown
chgrp
become much easier to understand.
Why Linux Has Permissions
Linux systems are often used by:
several users
several applications
web servers
databases
backup software
automated services
Those users and applications should not automatically have access to everything.
Permissions help prevent one process or user from:
reading private information
modifying application files
deleting another user's data
changing system configuration
replacing scripts
interfering with services
Permissions are therefore one of Linux's basic security boundaries.
Every File Has an Owner and a Group
Run:
ls -l
You might see:
-rw-r----- 1 carl marketing 2048 Aug 20 09:30 report.txt
The important parts are:
-rw-r-----
Permissions.
carl
Owner.
marketing
Group.
report.txt
Filename.
So this file belongs to user:
carl
and is associated with group:
marketing
The Three Permission Classes
Traditional Unix permissions divide access into three classes:
User
The file owner.
Shown as:
u
Group
Users who match the file's group.
Shown as:
g
Others
Everyone else.
Shown as:
o
GNU's current chmod documentation uses exactly these symbolic classes: u, g, o, and a for all three together.
The Three Basic Permissions
Each class can receive:
read
r
write
w
execute
x
But these mean slightly different things for files and directories.
File Permissions
For an ordinary file:
Read — r
Allows the contents to be read.
Write — w
Allows the contents to be changed.
Execute — x
Allows the file to be executed as a program or script, assuming everything else required to run it is valid.
Directory Permissions Are Different
This is one of the most important things to understand.
For a directory:
Read — r
Allows you to list the names inside it.
Write — w
Allows directory entries to be created, removed or renamed.
Execute — x
Allows you to traverse or enter the directory and reach files beneath it.
That means a user can sometimes know that a filename exists yet still be unable to open it because they do not have execute permission on one of the directories above it.
This is why:
namei -l /srv/projects/client/report.txt
is such a useful troubleshooting command.
It shows every component of the path.
Reading the Permission String
Take:
-rwxr-x---
The first character tells you the object type.
-
means ordinary file.
d
would mean directory.
The remaining nine characters split into three groups:
rwx r-x ---
Meaning:
Owner
rwx
Read, write and execute.
Group
r-x
Read and execute.
Others
---
No traditional permission.
Changing Permissions With chmod
chmod means:
change mode
You can use letters or numbers.
Add Execute Permission to the Owner
chmod u+x script.sh
Here:
u
means owner.
+
means add.
x
means execute.
Remove Group Write Permission
chmod g-w report.txt
Give Everyone Read Permission
chmod a+r guide.txt
Set Permissions Exactly
chmod u=rw,g=r,o= report.txt
That means:
owner: read/write
group: read
others: nothing
GNU's chmod documentation describes the same add, remove and exact-setting symbolic operations.
What Do Numbers Such as 644 and 755 Mean?
The numbers are simply shorthand.
Each permission has a value:
read = 4
write = 2
execute = 1
Add them together.
7
4 + 2 + 1
= read, write, execute
6
4 + 2
= read, write
5
4 + 1
= read, execute
4
= read only
The three digits represent:
owner group others
What Does 755 Mean?
7 5 5
becomes:
rwx r-x r-x
The owner can:
read
write
execute
Everyone else can:
read
execute
This is commonly used for directories and executable programs.
What Does 644 Mean?
6 4 4
becomes:
rw- r-- r--
The owner can read and write.
Everyone else can only read.
This is common for ordinary non-secret files.
Useful Permission Examples
600
rw-------
Only the owner can read or write.
Often appropriate for:
private keys
credential files
sensitive configuration
700
rwx------
Only the owner can access the directory or execute the file.
644
rw-r--r--
Common ordinary file permission.
755
rwxr-xr-x
Common directory or executable permission.
770
rwxrwx---
Owner and group have full access.
Useful for some shared directories.
These are examples, not universal rules.
The correct permissions depend on what the file or directory is supposed to do.
Changing Ownership With chown
To change the owner:
sudo chown carl report.txt
To change owner and group:
sudo chown carl:marketing report.txt
To change only the group:
sudo chown :marketing report.txt
or:
sudo chgrp marketing report.txt
Be Extremely Careful With Recursive Ownership
This:
sudo chown -R carl:marketing /srv/reports
changes ownership of:
the directory
every subdirectory
every file below it
That may be exactly what you intend.
Point it at the wrong directory and you can change ownership of thousands of files.
Before running a recursive command, check:
ls -ld /srv/reports
find /srv/reports -maxdepth 2 -ls
The command itself is easy.
The dangerous part is choosing the wrong target.
chmod -R 755 Is Usually a Poor Shortcut
You will often see advice such as:
sudo chmod -R 755 /srv/website
That gives execute permission to every file.
Most:
HTML
images
configuration files
text documents
do not need execute permission.
A cleaner approach is usually:
sudo find /srv/website -type d -exec chmod 755 {} +
for directories, then:
sudo find /srv/website -type f -exec chmod 644 {} +
for ordinary files.
Files and directories frequently need different modes.
Why 777 Is Usually the Wrong Fix
Permission:
777
means:
rwxrwxrwx
Everyone gets everything.
It is often used like this:
chmod 777 folder
because an application reports:
Permission denied
and 777 appears to make the error disappear.
But the real question should be:
Which account needs access?
Which group should be used?
Does it need read, write or execute access?
Grant the minimum access required.
A permissions error is not automatically solved correctly just because the error message goes away.
Why sudo Is Not the Universal Fix
Another bad habit is:
Permission denied
therefore:
sudo ...
Sometimes elevated privileges are genuinely required.
But first ask why your ordinary account lacks access.
Using sudo unnecessarily can create new problems.
For example:
sudo touch notes.txt
may create:
-rw-r--r-- root root notes.txt
Now your normal account may be unable to edit its own working file.
If that happened accidentally:
sudo chown carl:carl notes.txt
may be the appropriate correction.
Do Not Change Ownership of System Files Just to Make Them Easier to Edit
A file such as:
/etc/ssh/sshd_config
normally belongs to:
root
That is deliberate.
Do not run:
sudo chown carl /etc/ssh/sshd_config
just because you want to edit it.
Use an elevated editor instead:
sudoedit /etc/ssh/sshd_config
or an appropriate administrative editing method.
Preserve the intended ownership model.
Group Membership Is Often the Better Solution
Suppose several developers need access to:
/srv/project
Instead of making everybody individually own different files, create or use a shared group.
For example:
sudo chown root:developers /srv/project
sudo chmod 2770 /srv/project
Then add the appropriate users to:
developers
The leading:
2
in:
2770
enables the set-group-ID bit on the directory.
What Does Setgid Do on a Directory?
On a shared directory:
chmod g+s /srv/project
or:
chmod 2770 /srv/project
causes newly created files and directories to inherit the parent directory's group.
You may see:
drwxrws---
The:
s
in the group execute position shows the setgid bit.
This is extremely useful for collaborative folders because new content remains associated with the shared team group.
What Is the Sticky Bit?
A directory such as:
/tmp
is writable by many users.
But you generally do not want one ordinary user deleting another user's files.
That is where the sticky bit helps.
Check:
ls -ld /tmp
You will commonly see:
drwxrwxrwt
The final:
t
is the sticky bit.
You can apply it with:
chmod +t shared-folder
or:
chmod 1777 shared-folder
This is a legitimate example where 777-style base permissions can be paired with another protection mechanism—but it is a specialised directory design, not a generic permission fix.
What Is umask?
When software creates a file or directory, it starts from a default permission model.
umask removes permissions from those defaults.
Check your current value:
umask
A common value is:
0022
Broadly, that tends to produce new files such as:
644
and directories such as:
755
Another common collaborative setting is:
0002
which allows group write permission where the application creates files accordingly.
umask affects newly created objects.
It does not retroactively change existing files.
ACLs: When Owner/Group/Other Is Not Enough
Traditional Unix permissions can be too restrictive for real organisations.
Imagine:
file owner = Carl
file group = finance
Alice also needs read access
Alice should not join the entire finance group
Access Control Lists—ACLs—solve this.
View ACLs:
getfacl report.txt
Give Alice read access:
setfacl -m u:alice:r report.txt
Give another group read/write:
setfacl -m g:auditors:rw report.txt
Remove Alice's additional entry:
setfacl -x u:alice report.txt
Linux ACLs support additional named users and groups beyond the basic owner/group/other model.
The ACL Mask Can Surprise You
This is worth explaining because it causes genuine confusion.
An ACL might contain:
user:alice:rwx
but Alice's effective permissions may still be lower because an ACL mask limits the maximum permissions available to named users, named groups and the owning group.
The Linux ACL access algorithm specifically applies the mask when evaluating matching named-user and group ACL entries.
So when using:
getfacl
pay attention to comments such as:
#effective:r-x
The explicit entry is not always the final effective permission.
Default ACLs Are Useful for Shared Directories
A directory can also have a default ACL.
For example:
sudo setfacl -m d:g:sharedteam:rwx /srv/shared
This tells Linux to use that ACL when creating new objects inside the directory.
You may also want the access ACL on the directory itself:
sudo setfacl -m g:sharedteam:rwx /srv/shared
The Linux ACL specification explicitly distinguishes a directory's current access ACL from its default ACL, which is used when new objects are created beneath it.
Why ls -l Sometimes Shows a +
You might see:
-rw-r-----+
That final:
+
is a clue that additional ACL information exists.
At that point:
getfacl file
is much more informative than continuing to reason only from the basic nine permission bits.
Parent Directories Can Block Access
Suppose:
-rw-r--r-- report.txt
appears readable.
Yet the user still receives:
Permission denied
The problem may be one of the directories above it.
Run:
namei -l /srv/projects/client/report.txt
You might discover:
drwx------ root root projects
The file itself is readable.
The user cannot traverse the path to reach it.
This is one of the best tools for real permission troubleshooting.
Filesystems Can Be Read-Only
Permissions may look perfect and writes can still fail.
Check:
findmnt /path/to/file
Look for:
ro
rather than:
rw
A filesystem may become read-only because of:
deliberate mount configuration
recovery state
filesystem errors
storage faults
Changing:
chmod
will not fix a read-only filesystem.
SELinux and AppArmor Add Another Security Layer
Traditional permissions are not always the final decision.
Linux distributions may also use:
SELinux
AppArmor
These can restrict applications even when ordinary Unix permissions would allow access.
On SELinux systems:
getenforce
and:
sudo ausearch -m AVC -ts recent
can help identify denials.
For AppArmor:
sudo aa-status
Do not disable SELinux or AppArmor just because:
Permission denied
appears.
They may be correctly blocking something the application should not be doing.
Fix the correct policy or context instead.
A Better “Permission Denied” Troubleshooting Order
When Linux says:
Permission denied
work through this:
1. Who am I?
whoami
2. Which groups do I belong to?
id
3. Who owns the file?
ls -l file
4. What permissions does the directory have?
ls -ld directory
5. Can I traverse the complete path?
namei -l /full/path/to/file
6. Are ACLs involved?
getfacl file
7. Is the filesystem writable?
findmnt /full/path/to/file
8. Is SELinux or AppArmor denying the application?
Check the relevant security logs.
9. Change the smallest thing necessary
That might be:
chmod
chown
group membership
ACL
application policy
Do not default to:
777
or:
sudo everything
Test as the User Who Actually Needs Access
After changing permissions, verify the result using the real identity.
For example:
sudo -u carl cat /path/to/report.txt
If an application runs as:
www-data
test access as that user where appropriate.
The fact that root can access the file proves very little.
Root is not usually the account your service runs as.
Practical Examples
Make a script executable
chmod u+x backup.sh
Make a sensitive file private
chmod 600 credentials.conf
Ordinary readable document
chmod 644 guide.txt
Shared team directory
sudo chown root:developers /srv/project
sudo chmod 2770 /srv/project
Correct accidentally root-owned file
sudo chown carl:carl document.txt
Give Alice read access without changing the group
setfacl -m u:alice:r report.txt
Diagnose every permission in a path
namei -l /srv/project/reports/report.txt
The Permissions Rules Worth Remembering
You do not need to memorise every possible number.
Remember these principles:
Ownership tells you which user and group are associated with the object.
r, w and x behave differently for files and directories.
644 and 755 are common, not magical.
777 is rarely an appropriate repair.
sudo can hide the real problem.
Parent directories matter.
ACLs can add users and groups beyond the traditional model.
SELinux/AppArmor can still deny access even when Unix permissions look correct.
Recursive permission changes deserve extreme caution.
The safest rule is:
Grant the smallest amount of access needed to the correct identity.
How Hamilton Group Can Help
Linux permission problems can range from one incorrectly owned file to a business application that cannot access its data because several security layers interact.
Hamilton Group can help with:
Linux servers
file permissions
chmod
chown
users and groups
ACLs
shared directories
web-server permissions
SELinux and AppArmor
Linux troubleshooting
managed server support
For production systems, the objective should not simply be to make:
Permission denied
disappear.
It should be to restore the required access without giving users or services significantly more permission than they actually need.
Visit hgmssp.com or call 01423 438 953.
0 comments
- Be the first to comment.