Thuta Learning
ရှာဖွေရန်
IntermediateDevOps & Toolsbeginner

chmod နဲ့ permission ပြောင်းခြင်း

စိတ်လျှော့ပါ။ ဒီခန်းကို စာအုပ်လိုမဟုတ်ဘဲ စကားပြောသလိုပဲ၊ နားလည်လွယ်အောင် ရှင်းပါမယ်။

ဒီခန်းပြီးရင် ဘာတတ်သွားမလဲ

  • chmod နဲ့ permission ပြောင်းခြင်း ကို ကြောက်စရာမလိုအောင် နားလည်မယ်
  • Terminal ထဲမှာ ကိုယ်တိုင် command ကို စမ်းသုံးတတ်အောင် လုပ်မယ်
  • Real server/project မှာ ဒီ command ဘယ်လို အသုံးဝင်သလဲ ချိတ်မြင်မယ်

ခဏလေး ဒီလိုပဲ စဉ်းစားကြည့်

chmod (change mode) ကို ရေးနည်းနှစ်မျိုးနဲ့ သုံးလို့ရပါတယ် — Symbolic (u/g/o + +/- + r/w/x) နဲ့ Numeric (octal 0-7)။ Numeric method မှာ r=4, w=2, x=1 ကို ပေါင်းပါတယ် — 7 = rwx (4+2+1), 6 = rw- (4+2), 5 = r-x (4+1)။ chmod 755 file.sh ဆိုရင် owner=7(rwx), group=5(r-x), others=5(r-x) ဆိုတာပါ — script ဖိုင်တစ်ခုကို 'ကိုယ်တိုင် အပြည့်ထိန်းချုပ်, တခြားသူ run/ဖတ်ခွင့်ပဲပေး' ဆိုတဲ့ standard pattern ပါ။ Symbolic method မှာ chmod +x file.sh ဆိုရင် owner/group/others အားလုံးကို execute ခွင့် ထပ်ပေးလိုက်တာပါ — ရိုးရှင်းပြီး memorize လွယ်ပါတယ်။

လက်တွေ့ scenario နဲ့ ချိတ်ကြည့်မယ်

.sh script ဖန်တီးလို့ ./script.sh run ကြည့်ရင် bash: Permission denied ပေါ်လာရင် chmod +x script.sh လို့ ရိုက်ပါ, ပြီးရင် run ရပါပြီ။ Config ဖိုင်တစ်ခုကို ကိုယ့် user ကလွဲပြီး ဘယ်သူမှ မဖတ်စေချင်ရင် (password ပါတဲ့ဖိုင်လိုမျိုး) chmod 600 file (owner rw-, group/others ဘာမှမရ) သုံးလေ့ရှိပါတယ် — SSH key ဖိုင်တွေမှာ ဒီ permission မမှန်ရင် SSH ကိုယ်တိုင် ငြင်းပယ်ပါလိမ့်မယ်။

အတူတူ terminal ထဲ စမ်းမယ်

bash
echo 'echo hello' > script.sh
./script.sh          # Permission denied
chmod +x script.sh
./script.sh           # hello

chmod 600 secret.txt   # owner ပဲ ဖတ်/ရေးနိုင်
chmod 755 script.sh    # owner all, others read+run
You should see
chmod +x ပြီးနောက် ./script.sh run ရင် hello ပြန်ထွက်လာမည်။

၅ မိနစ် စမ်းကြည့်

script.sh ဖိုင်တစ်ခု ဖန်တီးပါ (echo command ပါစေ)။ chmod မလုပ်ဘဲ run ကြည့်ပြီး error မှတ်ပါ။ ပြီးရင် chmod +x လုပ်ပြီး ပြန် run ကြည့်ပါ။

သတိလေးတစ်ချက်

chmod 777 ကို 'ပြဿနာဖြေရှင်းချက်' အဖြစ် လမ်းလွှဲ မသုံးပါနှင့် — ဘယ်သူမဆို ဖိုင်ကို ဖတ်/ရေး/run နိုင်တာမို့ production server မှာ လုံးဝ မလုပ်သင့်ပါ။

ဒီနေရာမှာ လူအများမှားတတ်တယ်

  • chmod 777 (အားလုံးကို ခွင့်အပြည့်) ကို 'error ဖြေရှင်းရေးနည်း' လို့ လွယ်လွယ်ကူကူ သုံးမိခြင်း — security risk ကြီးမား
  • chmod ကို ဖိုင် owner ပြောင်းတဲ့ command လို့ ရောနားလည်ခြင်း (ဒါက chown ရဲ့ အလုပ်ပါ, နောက်ခန်းမှာ)

အခု ကိုယ်တိုင် စမ်းကြည့်

script.sh ဖိုင်တစ်ခု ဖန်တီးပါ (echo command ပါစေ)။ chmod မလုပ်ဘဲ run ကြည့်ပြီး error မှတ်ပါ။ ပြီးရင် chmod +x လုပ်ပြီး ပြန် run ကြည့်ပါ။

You'll know it worked when: chmod +x ပြီးနောက် ./script.sh run ရင် hello ပြန်ထွက်လာမည်။

chmod နဲ့ permission ပြောင်းခြင်း | Thuta Learning