Lesson 10 / الدرس 10

Permissions: rwx, and why 644 and 755 / الصلاحيات: rwx ولماذا 644 و755

That column of letters in ls -l decides who may read, change and run every file on the machine. Two numbers cover almost every case you will meet on a web server.

عمود الحروف ذاك في ls -l يقرر من يجوز له قراءة كل ملف على الجهاز وتغييره وتشغيله. ورقمان يغطيان كل حالة تقريبًا ستقابلها على خادم ويب.

Every file has an owner, a group, and three sets of permissions: what the owner may do, what members of the group may do, and what everyone else may do. Three audiences, three permissions each, nine letters — which is exactly the column you have been looking at since lesson 3.

-rwxr-xr--   1 ahmed  staff   index.php
 │└┬┘└┬┘└┬┘
 │ │  │  └── everyone else: read only
 │ │  └───── the group:     read and execute
 │ └──────── the owner:     read, write and execute
 └────────── the type:      - a file, d a directory
Ten characters: one for the type, then three groups of three. Each group is always in the same order — r then w then x — and a dash means that permission is absent. Run the demonstration to take one apart yourself.

Where the numbers come from

Read is worth 4, write 2 and execute 1. Add up what each audience may do and you get one digit for each — so rwx r-x r-- is 7, 5, 4, written 754. It looks arcane and it is only addition; after writing three of them you stop needing to work it out.

NumberLettersUse it for
644rw- r-- r--Ordinary files on a web server
755rwx r-x r-xDirectories, and programs
600rw- --- ---Anything private — an SSH key, a config file
700rwx --- ---A private directory
777rwx rwx rwxNever. See the warning below

Two of these cover nearly everything: 644 for files, 755 for directories. Change them with chmod 644 index.php.

Execute means something different on a directory

On a file, x means "may be run as a program". On a directory it means "may be entered" — you cannot cd into a directory without it, even if you can read it. That is why directories are 755 and files are 644: the directory needs the x to be usable at all, and an ordinary HTML file has no business being executable.

chown ahmed:staff file changes the owner and the group; it needs administrator rights, so it usually comes with sudo in front. This is the fix when a web server cannot write to a folder: the folder belongs to you and the server runs as somebody else. This very site hit exactly that during its first deployment — pages rendered and every submission failed, because the files had arrived owned by the wrong account.

Try it live / جرّب بنفسك

Preview / المعاينة

Check yourself / اختبر نفسك

1. What does 644 mean in letters?

2. Why do directories need x when files usually should not have it?

3. A web server cannot write to your uploads folder. What is the right fix?

Your task / مهمتك

Take five files and folders from your own machine with genuinely different permissions — include a private one such as an SSH key if you have one — and present them as a table: the letters, the equivalent number, who may do what, and whether you think it is right. Then change one file's permissions with chmod, showing ls -l before and after.

خذ خمسة ملفات ومجلدات من جهازك بصلاحيات مختلفة فعلًا — وأدرج واحدًا خاصًا كمفتاح SSH إن كان لديك — واعرضها في جدول: الحروف، والرقم المكافئ، ومن يجوز له ماذا، وهل تراه صحيحًا. ثم غيّر صلاحيات ملف واحد بـchmod، مُظهرًا ls -l قبل وبعد.

  • Five real entries, with letters and numbers for each خمسة مداخل حقيقية، بالحروف والأرقام لكل واحد
  • A directory and a file, so the two meanings of x appear مجلد وملف، ليظهر معنيا x
  • One chmod, with ls -l before and after chmod واحد، مع ls -l قبل وبعد
  • Your judgement on whether each is right حكمك على صحة كل واحد
How do you want to submit? / كيف تريد التسليم؟