Skip to main content

Manage Linux Web Server File Permissions With Chmod & Chown

Learn how to configure proper file permissions and user ownership on Linux for NGINX and Apache to fix 403 errors and secure your web server.

AI-written
Inewgen
17 Sep 2026Source: Dev.to3 min read (0 views)
Share
Manage Linux Web Server File Permissions With Chmod & Chown

Stock photo for illustration only, not from the actual event

Font size
  • Incorrect file permissions on Linux web servers are a leading cause of 403 errors and security flaws.
  • Use the chown command to assign your user as owner and the www-data group as group owner.
  • Use the chmod command to restrict file and directory access to secure boundaries.
  • Proper permission setups let you edit files cleanly without constantly relying on sudo.

Incorrect file permissions on Linux web servers are one of the most common causes of 403 Forbidden errors and server security vulnerabilities. If your web server process, such as NGINX or Apache, cannot read your website files, it cannot serve them to users. Conversely, if file permissions are set too loosely, unauthorized users can modify your code.

In this hands-on tutorial, you will learn how to configure proper user ownership and file permissions for a Linux web directory using chown and chmod to keep your environment running smoothly and securely.

terminal command line linux ubuntu screen

Stock photo for illustration only, not from the actual event

On Linux, every file and directory is assigned an owner and a group. Web servers like Apache and NGINX usually run under a dedicated system user, such as www-data or nginx. To check the current ownership of your web directory, typically located at /var/www/html, open your terminal and run:

ls -ld /var/www/html

If the owner is set to root, your regular user account won't be able to edit website files without using sudo.

Never miss the latest news?

Subscribe to get news summaries by email - not often enough to be annoying.

โฆษณา

Understanding the UGO (User, Group, Others) permission model on Linux is essential for system administrators. Even a minor configuration oversight can allow malicious actors to exploit your web server. Utilizing a dedicated group like www-data alongside restricted permissions acts as a vital security barrier, separating system administration rights from web service processes.

To allow your user account to edit files while giving the web server read access, assign your regular user as the owner and the web server group, www-data, as the group owner:

sudo chown -R $USER:www-data /var/www/html

  • -R: Applies the ownership change recursively to all files and subdirectories.
  • $USER: Environment variable representing your logged-in username.
  • www-data: The web server group name.

Verify the update by running ls -ld /var/www/html, where the output should display your username and the www-data group.

Moving forward, configuring secure file and directory permissions with chmod determines what the Owner (u), Group (g), and Others (o) can do. Your regular user can now edit website contents cleanly without sudo, and your web server process retains read access while maintaining a secure permission boundary.

Source: Dev.to

Comments

Leave a Comment
0/2000

Found something wrong in this article? Report an issue with this article