October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
VGSources
Blog

How to Change Linux File Permissions and Owners Safely

A practical Linux guide to changing permission bits, file owners, and groups without accidentally exposing files, executing every document, or following symlinks into the wrong tree.
Length9 min Posted Quest giverVGSources Team
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use chmod to change read, write, and execute permissions; use chown to change a file’s user owner (and optionally its group); and use chgrp when only the group should change. Inspect the current mode and owner first, make the smallest change that fixes the problem, and treat recursive commands as potentially destructive. Only root can assign a different user as owner, while an ordinary user can change a file’s group only to a group that user belongs to.

The Linux permission model in one minute

Every file and directory has two separate kinds of access control:

As an Amazon Associate I earn from qualifying purchases.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Permission bits: read (r), write (w), and execute (x) permissions for the owner, the owning group, and everyone else. chmod changes these bits.
  • Ownership: one user and one group attached to the inode. chown changes the user and, if requested, the group; chgrp changes only the group.

These controls are independent. A web server, game server, or container can report “Permission denied” because the process has the wrong owner or group even when the mode looks permissive, or because the mode blocks an otherwise correct owner. Check both before changing either.

Check the current owner, group, and mode before editing

Start with a listing that shows the nine permission bits, owner, group, size, and path:

ls -l /path/to/file
ls -ld /path/to/directory

Use ls -ld for a directory itself. Without -d, ls -l shows the directory’s contents instead, which can lead you to change the wrong object. A line such as -rw-r----- alice games save.dat means a regular file, owner alice, group games, owner permissions rw-, group permissions r--, and no permissions for others.

Confirm the account and group names that exist on this machine:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
id
id username
getent group games

If a path is a symbolic link, inspect both the link and its target:

ls -l /path/to/link
readlink /path/to/link

This distinction matters because many ownership commands follow a symlink and modify its target by default.

Choose the right command

Command Changes Typical use
chmod Read, write, and execute bits for owner, group, and others Allow a script to run, remove write access from other users, or set a directory’s traversal permissions
chown User owner, with an optional group change Give a service account ownership of a game-server directory or uploaded files
chgrp Group owner only Move a shared directory into a team group without changing its user owner

Changing the mode cannot change who owns a file, and changing ownership cannot add a missing execute bit to a directory. Solve the specific control that is wrong instead of applying a broad command “just in case.”

Change permissions with chmod

Numeric (octal) mode

A numeric mode has one digit for each class in this order: owner, group, others. Within each digit, read is 4, write is 2, and execute is 1; add the values for the permissions you want.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Digit Bits Meaning
0 --- No access
1 --x Execute (or traverse for a directory)
2 -w- Write
3 -wx Write and execute
4 r-- Read
5 r-x Read and execute
6 rw- Read and write
7 rwx Read, write, and execute

Examples:

chmod 644 config.ini
chmod 755 start-server.sh
chmod 700 private-save-directory
  • 644 gives the owner read/write access and everyone else read-only access. It is a common choice for text, configuration, and save files that do not need to run.
  • 755 gives the owner full access and group/others read and execute access. It is appropriate for an executable script or a directory that others must traverse, but it is usually too permissive for ordinary documents.
  • 700 keeps a private directory accessible only to its owner.

A leading fourth digit can represent special bits such as set-user-ID, set-group-ID, or the sticky bit. For a shared directory, the set-group-ID form is commonly written as 2775; the leading 2 makes newly created files inherit the directory’s group.

Symbolic mode

Symbolic syntax identifies the class, an operator, and the bits: u (user/owner), g (group), o (others), or a (all three), followed by + to add, - to remove, or = to set exactly.

chmod a=r,u+w notes.txt
chmod g-w,o-rwx shared-save
chmod u+x start-server.sh

The first example sets read-only access for everyone, then adds owner write access, resulting in owner rw- and group/others r--. Symbolic mode is useful when you want to preserve unrelated bits—for example, adding execute for the owner without replacing existing group permissions.

Files and directories need different permissions

On a regular file, read permits opening its contents, write permits modifying or truncating them, and execute permits running it as a program. A text-based game configuration normally needs read/write for its service account but does not need execute.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

On a directory, read permits listing names, write permits creating, deleting, or renaming entries, and execute permits traversing the directory and accessing entries when their names are known. A user may therefore need x on every parent directory in a path even if the target file itself is readable.

Do not use a blanket chmod -R 755 on a tree of documents, saves, or configuration files. It marks every regular file executable. If you intentionally need a broad recursive adjustment while avoiding that mistake, the GNU manual demonstrates:

chmod -R a=,+rwX project-directory

Here X adds execute only to directories and to files that were already executable. Review the result with find or ls -l before exposing the tree to a service or other users; a targeted command for a known set of files is safer than any blanket change.

Change the owner or group with chown

Set the user owner

sudo chown gameserver /srv/game-server/save.dat

Only root can change a file’s user owner. Use sudo when your account is allowed to administer the machine. If the target user does not exist, the command fails rather than creating an account.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Set both user and group

sudo chown gameserver:games /srv/game-server
sudo chown gameserver:games /srv/game-server/save.dat

The user:group form is explicit and easier to audit. It is the preferred form when a service must run as one account while sharing files with a named group.

Change only the group with chown or chgrp

sudo chown :games /srv/game-server/mods
sudo chgrp games /srv/game-server/mods

A leading colon with no user changes only the group; chgrp expresses that intention directly. An ordinary user can select only a group that user belongs to. Root can assign any existing group.

On GNU chown, writing a user followed by a colon with no group (for example, chown gameserver: file) sets the user owner and the owner’s login group. Ubuntu 25.10 and newer use the Rust-based uutils implementation by default; a report from one Ubuntu 26.04 test found chown USER: FILE changed the owner but left the group unchanged. Because that behavior may vary by implementation, specify USER:GROUP whenever the group matters. GNU chown remains available on those systems as gnuchown.

Apply changes recursively without damaging a tree

Add -R to recurse through a directory and its contents:

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
sudo chown -R gameserver:games /srv/game-server
sudo chmod -R 750 /srv/game-server

Recursion affects every descendant, including files that may need different modes, generated logs, sockets, and links. Prefer separate passes when files and directories need different policies. For example, set directory traversal and file readability independently after inspecting the tree, rather than forcing one mode onto everything.

Take a dry look first:

find /srv/game-server -maxdepth 2 -printf '%M %u %g %pn'

Save the current ownership and mode information or make a backup before a large change. If a command reports an error partway through, do not assume the entire tree changed; inspect representative files and rerun a narrower command.

Handle symbolic links deliberately

By default, chown follows a symbolic link and changes the target. To change the link object itself, use -h:

sudo chown -h gameserver:games /srv/game-server/current

For chgrp, -h or the long option --no-dereference requests the link itself. The manual also documents -H and -R combinations for recursive operations. Be especially cautious with recursive ownership changes in directories containing links to locations outside the intended project; following those links can alter files elsewhere.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

chmod generally operates on the target reached through a symbolic link because a link has no independent permission bits that control access. If you need to protect the target, resolve the path and change the real file deliberately.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Build a safe shared directory for a game project

Suppose an administrator and a deployment account both maintain files in /srv/game-server, and both are members of the games group. A controlled setup is:

  1. Create or verify the group and membership using your distribution’s account-management tools, then start a new login session so group membership is refreshed.
  2. Assign the service account and group explicitly:
    sudo chown -R gameserver:games /srv/game-server
  3. Set the directory’s set-group-ID bit and a group-writable mode:
    sudo chmod 2775 /srv/game-server
  4. Give ordinary files only the access they need. Do not make configuration files executable merely because the parent directory is executable.
  5. For users who need exceptions beyond owner/group/other, use POSIX ACL tools: setfacl to grant a named user or group and getfacl to inspect the resulting ACL. ACL entries supplement the basic mode; document them so a later chmod change does not surprise the team.

The set-group-ID directory causes new entries to inherit the directory’s group, which prevents each contributor’s private login group from fragmenting access. It does not, by itself, make every new file group-writable; the creating program’s mode and the process umask still matter.

Fix “Permission denied” methodically

Work from the path outward rather than repeatedly adding permissions:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  1. Identify the process account. A service launched by systemd, a container, or a game panel may run as a different user than your shell. Confirm that account and its supplementary groups.
  2. Inspect every parent directory. The process needs execute permission on each directory in the path. A readable target file is not enough if a parent directory blocks traversal.
  3. Check owner and group. Use ls -ld on each directory and ls -l on the target. Correct ownership with chown user:group only when the service should own the data; otherwise use a shared group.
  4. Check the mode. Add the minimum required bit with symbolic chmod where possible. Avoid making a file world-writable or an entire tree executable as a shortcut.
  5. Check ACLs. getfacl path can reveal a named-user entry or a mask that changes the effective permission shown by the basic mode.
  6. Check links and mounts. A symlink may lead to a target with different ownership, and a mounted filesystem may impose its own rules. Resolve the path before changing anything recursively.

Many web-server and Docker deployment failures attributed to “permissions” are ownership mismatches: the process is running under an account that cannot write files created by an administrator. Correcting the owner or shared group is safer than setting 777, which grants write access to everyone.

Common mistakes and their safer replacements

Mistake Why it causes trouble Safer approach
chmod -R 777 project Every local user and service can modify every descendant. Set a service owner or shared group, then grant only the required group bits.
chmod -R 755 project Regular files become executable, and sensitive files may be readable by others. Use separate directory and file policies; use X only when a recursive operation is truly needed.
Changing only the target file A parent directory without execute permission still blocks access. Inspect and fix traversal permissions on every parent directory.
Using chown -R on a tree containing links Default symlink handling can modify link targets. Inspect links first and use -h or a narrower path when the link itself is the object you intend to change.
Assuming chown USER: has identical behavior everywhere GNU and uutils implementations can differ on the omitted-group case. Write USER:GROUP explicitly and verify with ls -l.

Quick command reference

Goal Command
Inspect a file ls -l file
Inspect a directory itself ls -ld directory
Make a file owner-read/write, others-read chmod 644 file
Make an owner-run script executable chmod u+x script.sh
Set owner and group sudo chown user:group path
Set only the group sudo chgrp group path
Change ownership recursively sudo chown -R user:group directory
Change a symlink’s own owner sudo chown -h user:group symlink
Set group inheritance on a shared directory sudo chmod 2775 directory
Inspect extended ACLs getfacl path

A final safety checklist

  • Confirm the exact path; use ls -ld before changing a directory.
  • Decide whether the problem is mode, owner, group, ACL, or parent-directory traversal.
  • Use the narrowest command and explicit user:group notation.
  • Use sudo only for the command that requires administrative rights.
  • Review symlinks before recursive operations; use -h or --no-dereference when the link itself must change.
  • Verify the result with ls -l, ls -ld, and, when relevant, getfacl.
  • On Ubuntu 25.10 or newer, verify which chown implementation is active and specify the group explicitly.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More quests from Patch Notes

  1. How to Set Up a RedM (RDR2) Server in 2026: License Key, txAdmin and server.cfg, Step by StepBlog11min
  2. Best RedM (RDR2) Server Hosting in 2026: Comparing Four Hosts on Slots, Memory and PriceBlog10min
  3. How to Host a Mindustry Server in 2026: server-release.jar, Port 6567 and the Commands That MatterBlog7min
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.