Linux Users, Groups, and File Permissions: chmod, chown, umask
Understand Linux permission bits, ownership, group-based access control, and how umask shapes default file modes.
Netbay Developer Relations
Netbay Engineering
On this page
Every file and directory on a Linux system belongs to a user and a group. Permissions control who can read, write, and execute that file. Understanding these concepts is essential for running web servers, databases, and any multi-user service on a VPS without accidentally exposing sensitive data.
Permission Bits Explained
When you run ls -l, the first column shows a ten-character string like -rwxr-xr--. The first character identifies the file type: - for regular files, d for directories, l for symlinks. The remaining nine characters are three sets of three bits: owner, group, and others.
- **r (read)**: For files, allows reading contents. For directories, allows listing entries.
- **w (write)**: For files, allows modifying contents. For directories, allows creating or deleting files inside.
- **x (execute)**: For files, allows running as a program. For directories, allows traversing into it.
A common mistake is giving files 777 permissions to fix a "permission denied" error. This grants every user on the system full read, write, and execute access. Instead, identify which user the service runs as and grant the minimum required permissions.
Changing Permissions with chmod
The chmod command modifies permission bits. You can use symbolic mode or numeric (octal) mode:
chmod 644 index.html
chmod 755 /usr/local/bin/myapp
chmod u+x deploy.sh
chmod go-w /var/www/uploadsNumeric mode is compact but requires understanding octal. 644 means owner can read+write (4+2=6), group can read (4), others can read (4). 755 means full access for the owner and read+execute for everyone else, which is correct for directories and executables.
Symbolic mode is more readable for targeted changes. u+x adds execute for the owner, go-w removes write for group and others. You can combine multiple symbolic operations with commas: chmod u+rwx,g+rx,o+r file.
Ownership with chown
The chown command changes user and group ownership:
chown www-data:www-data /var/www/html -R
chown deploy:deploy /opt/app/currentWeb servers typically run as a dedicated user like www-data or nginx. Your application files should be owned by that user or a shared group so the web server can read them without granting excessive permissions. For deployment workflows, a common pattern is to set group ownership to a deploy group and grant group write access.
Understanding umask
The umask determines the default permissions for newly created files and directories. A typical umask is 022, which means new files get 644 (666 minus 022) and directories get 755 (777 minus 022).
You can check your current umask:
umask
umask -STo make a stricter umask permanent for a user, add it to ~/.bashrc:
umask 027A umask of 027 gives the group no access and others only read on files, which is appropriate for multi-user systems where you want to prevent users from reading each other's home directories.
Setgid and the Sticky Bit
Two special permission bits extend the basic model. The setgid bit on a directory forces new files to inherit the directory's group, which is invaluable for shared project directories:
chmod g+s /var/www/shared/The sticky bit on a directory like /tmp prevents users from deleting files they do not own:
chmod +t /var/tmpTogether, these bits let you build clean collaborative directories without exposing files to unintended users.
Takeaway
Permissions are not just a technical detail, they are your first line of defense. Set the right ownership with chown, use the most restrictive chmod mode that works, and lock down your umask. Deploy on a Netbay Linux VPS and apply these practices from day one at netbayhosts.in.
Keep reading
Follow along on a real VPS
Deploy Linux in under 60 seconds
These guides are written against Ubuntu, Debian, and RHEL-family images — the same ones on NetBay.
Deploy an instance