Arama Yap Mesaj Gönder
Biz Sizi Arayalım
+90
X
X
X
X

Knowledge Base

Homepage Knowledge Base General Linux File Permissions: Securing wi...

Bize Ulaşın

Konum Halkalı merkez mahallesi fatih cd ozgur apt no 46 , Küçükçekmece , İstanbul , 34303 , TR

Linux File Permissions: Securing with Chmod and Chown

Setting file and folder permissions correctly on web servers is crucial for both security and the proper functioning of the system. In Linux environments, file/folder permissions can be changed with chmod, and file/folder ownership can be changed with chown. Below, we discuss the purpose and what these commands do in detail.


1. Setting Folder Permissions (chmod)

sudo chmod -R 0755 uploads2

Explanation:

  • chmod: Used to assign permissions to a file or folder.

  • -R: Applies recursively (including subfolders and all files within).

  • 0755:

    • Owner: read, write, execute (7)

    • Group: read, execute (5)

    • Other: read, execute (5)

Purpose: Ensures that the web server can read and execute files, but prevents unauthorized individuals from making changes.


2. Changing File Ownership (chown)

sudo chown -R eka:eka uploads2

Explanation:

  • chown: Changes ownership.

  • -R: Applies recursively, including subdirectories.

  • eka:eka: Changes the user name to eka and the group name to eka.

  • uploads2: The folder whose ownership will be changed.

Purpose: Ensures that Laravel or PHP applications belong to the correct user so they can write files.


3. Assigning Ownership to the Web Root Directory

sudo chown -R eka:eka /home/eka/public_html

Explanation:
This command gives ownership of all files and folders in the /home/eka/public_html directory to the eka user and the eka group.

Purpose:

  • In hosting or VPS environments, it is expected that only the user has write permissions in their public_html directory.

  • It is desired that the web server (Apache, Nginx, etc.) can access this directory but cannot write to it without permission.


Important Notes:

  • 755 is generally sufficient for directories, 644 can be used for files.

  • Avoid using 777, as it gives full permissions to all users and poses a security risk.

  • The Apache/Nginx system user is usually www-data, apache, or nginx; group permissions should also be adjusted as needed.


In Linux, the chmod and chown commands are essential tools for managing your server's file structure in an organized and secure manner. Properly setting these permissions is crucial for web applications to function correctly.

 

Can't find the information you are looking for?

Create a Support Ticket
Did you find it useful?
(315 times viewed / 130 people found it helpful)

Call now to get more detailed information about our products and services.

Top