Chapter 3: Linux Basic Commands
3.5 Permissions
Friends, most "403 Forbidden" and "Permission denied" problems come from this very topic, so pay attention. Once r, w and x are clear, half of your troubleshooting is already done.
मित्रांनो, "403 Forbidden" आणि "Permission denied" चे बहुतेक प्रॉब्लेम्स याच टॉपिकमधून येतात, म्हणून लक्ष द्या. एकदा r, w आणि x नीट समजले की तुमचं अर्धं ट्रबलशूटिंग आधीच झालं.
दोस्तों, "403 Forbidden" और "Permission denied" के ज़्यादातर प्रॉब्लम्स इसी टॉपिक से आते हैं, इसलिए ध्यान दो. एक बार r, w और x ठीक से समझ आ गए तो आपकी आधी ट्रबलशूटिंग पहले ही हो गई.
Every file has an owner (u), a group (g) and others (o). Each can have read (r), write (w) and execute (x) permission.
| Permission | On a file | On a directory | Value |
|---|---|---|---|
| r (read) | View contents | List files (ls) |
4 |
| w (write) | Modify contents | Create/delete files inside | 2 |
| x (execute) | Run as program/script | Enter the directory (cd) |
1 |
Numeric (octal) notation — add the values for each of user, group, others:
| Octal | Symbolic | Meaning | Typical use |
|---|---|---|---|
| 777 | rwxrwxrwx |
Everyone everything | Avoid — insecure |
| 755 | rwxr-xr-x |
Owner full, others read+enter | Directories, scripts, web folders |
| 750 | rwxr-x--- |
Owner full, group read, others nothing | Private app directories |
| 700 | rwx------ |
Only owner | ~/.ssh directory |
| 644 | rw-r--r-- |
Owner write, others read | Web files (HTML, CSS), configs |
| 640 | rw-r----- |
Owner write, group read | Config with passwords (wp-config.php) |
| 600 | rw------- |
Only owner read/write | ~/.ssh/authorized_keys |
| 400 | r-------- |
Only owner read | .pem private key |
chmod 755 deploy.sh # numeric
chmod u+x deploy.sh # symbolic: add execute for user
chmod go-w file.txt # remove write from group and others
chmod -R 755 /var/www/html # recursive
chmod 400 mykey.pem # required before using an SSH key
sudo chown nginx:nginx /usr/share/nginx/html/index.html # owner:group
sudo chown -R www-data:www-data /var/www/html # Ubuntu web user
sudo chown -R apache:apache /var/www/html # AL2023/CentOS Apache user
Safe web permissions
A common, safe pattern: directories 755, files 644, owned by your login user or the web-server user. Set them in one go:
sudo find /var/www/html -type d -exec chmod 755 {} \; and sudo find /var/www/html -type f -exec chmod 644 {} \;
For the Mauli Dairy website you need these three numbers every day: 755 for folders, 644 for HTML and CSS files, and, for the key on your laptop, .pem gets 400. All other numbers are just variations around these.
Mauli Dairy च्या वेबसाइटसाठी हे तीन नंबर्स रोज लागतात: फोल्डर्स 755, HTML आणि CSS फाइल्स 644, आणि तुमच्या लॅपटॉपवर .pem की 400. बाकी सगळे नंबर्स यांच्याच आजूबाजूचे आहेत.
Mauli Dairy की वेबसाइट के लिए ये तीन नंबर्स रोज़ चाहिए: फ़ोल्डर्स 755, HTML और CSS फ़ाइलें 644, और आपके लैपटॉप पर .pem की 400. बाकी सारे नंबर्स इन्हीं के आस-पास के हैं.
Ravindra Bagale's Tip
Before changing permissions on a live server, always run ls -l first and note down the original values. And please, never use chmod -R 777 to "fix" an error – it only hides the real problem and opens a security hole. Find out which user needs access, and give only that much access. That's all.
Ravindra Bagale's Tip – मराठी
Live server वर permissions बदलण्याआधी नेहमी आधी ls -l चालवा आणि original values लिहून ठेवा. आणि please, error "fix" करायला कधीच chmod -R 777 वापरू नका – ते फक्त खरा problem लपवतं आणि security hole उघडतं. कोणत्या user ला access पाहिजे ते शोधा, आणि तेवढाच access द्या. बस इतना ही.
Ravindra Bagale's Tip – हिंदी
Live server पर permissions बदलने से पहले हमेशा पहले ls -l चलाओ और original values लिख लो. और please, error "fix" करने के लिए कभी chmod -R 777 इस्तेमाल मत करो – वो सिर्फ़ असली problem छुपाता है और security hole खोल देता है. किस user को access चाहिए वो ढूँढो, और उतना ही access दो. बस इतना ही.
Ravindra Bagale's Tip
A common mistake is giving a folder 644 – then you cannot cd into it and Nginx returns 403. Remember: entering a directory needs x, so folders get 755 and files 644. After that, check the owner with ls -l.
Ravindra Bagale's Tip – मराठी
एक common चूक म्हणजे folder ला 644 देणं – मग cd करता येत नाही आणि Nginx 403 देतो. लक्षात ठेवा: directory मध्ये जाण्यासाठी x लागतो, म्हणून folders 755 आणि files 644. त्यानंतर owner ls -l ने check करा.
Ravindra Bagale's Tip – हिंदी
एक common गलती है folder को 644 देना – फिर cd नहीं कर पाते और Nginx 403 देता है. याद रखो: directory में जाने के लिए x चाहिए, इसलिए folders 755 और files 644. उसके बाद owner को ls -l से check करो.
Lab
Chala, ~/labs/mauli madhe deploy.sh banva, ls -l ne tyache permissions liha, mag chmod 755 deploy.sh aani chmod u-x deploy.sh karun pratyek veli ls -l madhe badal bagha. Shevti rwxr-x--- cha numeric value swatah kadha aani chmod ne lavun check kara.
Got it? r=4, w=2, x=1 – once you can read these three numbers and the output of ls -l, most permission problems get solved. Now let's move on to users and sudo.
समजलं का? r=4, w=2, x=1 – हे तीन नंबर्स आणि ls -l चा आउटपुट वाचता आला की परमिशन्सचे बहुतेक प्रॉब्लेम्स सुटतात. आता पुढे जाऊया यूजर्स आणि sudo कडे.
समझ आया? r=4, w=2, x=1 – ये तीन नंबर्स और ls -l का आउटपुट पढ़ना आ गया तो परमिशन्स के ज़्यादातर प्रॉब्लम्स सुलझ जाते हैं. अब आगे चलते हैं यूज़र्स और sudo की तरफ़.