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
r then w then x — and a dash means that permission is absent. Run the demonstration to take one apart yourself.
r ثم w ثم x — والشَّرطة تعني غياب تلك الصلاحية. شغّل العرض لتفكك واحدة بنفسك.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.
rwx r-x r-- هي 7 و5 و4، وتُكتب 754. تبدو غامضة وهي جمع ليس إلا؛ وبعد كتابة ثلاث منها تكفّ عن الحاجة إلى حسابها.| Number | Letters | Use it for |
|---|---|---|
| 644 | rw- r-- r-- | Ordinary files on a web server |
| 755 | rwx r-x r-x | Directories, and programs |
| 600 | rw- --- --- | Anything private — an SSH key, a config file |
| 700 | rwx --- --- | A private directory |
| 777 | rwx rwx rwx | Never. See the warning below |
Two of these cover nearly everything: 644 for files, 755 for directories. Change them with chmod 644 index.php.
644 للملفات و755 للمجلدات. وتُغيَّر بـ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.
x "يجوز تشغيله برنامجًا". وعلى المجلد تعني "يجوز دخوله" — فلا تستطيع cd إلى مجلد بدونها، وإن استطعت قراءته. ولهذا كانت المجلدات 755 والملفات 644: فالمجلد يحتاج x ليكون صالحًا أصلًا، وملف HTML عادي لا شأن له بأن يكون قابلًا للتنفيذ.chmod 777 أشيع نصيحة سيئة على الإنترنت. فهي تعني أن للجميع قراءة الملف وتغييره وتشغيله — وعلى خادم مشترك يشمل "الجميع" كل حساب آخر على ذلك الجهاز. وهي تُقترح لأنها تُذهب خطأ الصلاحيات، وتُذهبه بإزالة الحماية لا بإصلاح السبب. والإصلاح الحقيقي هو chown في الغالب: فالملف يخص المستخدم الخطأ.
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.
chown ahmed:staff file يغيّر المالك والمجموعة؛ ويحتاج صلاحيات إدارية، فيأتي عادةً وsudo أمامه. وهذا هو الإصلاح حين لا يستطيع خادم ويب الكتابة في مجلد: فالمجلد يخصك والخادم يعمل باسم شخص آخر. وقد وقع هذا الموقع نفسه في ذلك بالضبط في أول نشر له — فكانت الصفحات تُعرض وكل تسليم يفشل، لأن الملفات وصلت مملوكة للحساب الخطأ.chmod +x deploy.sh يجعل نصًا قابلًا للتشغيل، وchmod -w notes.txt يجعل ملفًا للقراءة فقط، وchmod go-r secret.txt ينزع القراءة من المجموعة ومن الجميع ويترك وصولك أنت.Try it live / جرّب بنفسك
Check yourself / اختبر نفسك
1.
What does 644 mean in letters?
644 بالحروف؟Read is 4 and write is 2, so 6 is read and write for the owner, and 4 is read only for the other two. It is the standard for an ordinary file on a server.
2.
Why do directories need x when files usually should not have it?
x بينما لا ينبغي للملفات عادةً أن تملكها؟The same letter means two different things. Without x you cannot cd into a directory at all, whatever else you are allowed to do.
x لا تستطيع cd إلى المجلد إطلاقًا، مهما جاز لك غير ذلك.3. A web server cannot write to your uploads folder. What is the right fix?
The problem is ownership, not strictness. 777 makes the symptom go away by removing the protection — on a shared machine, from every other account too.
777 يُذهب العرَض بإزالة الحماية — وعلى جهاز مشترك، من كل حساب آخر أيضًا.Score / النتيجة: 0 / 3
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 حكمك على صحة كل واحد