Linux Standard file permissions

Table of contents
အားလုံးပဲ မင်္ဂလာပါ။ Heinux blog မှ ကြိုဆိုလိုက်ပါတယ်။
ဒီနေ့မှာတော့ ကျွန်တော်က Linux မှာ file permissions တွေနဲ့ပတ်သက်ပြီး ဘယ်လိုသတ်မှတ်ချက်တွေရှိလဲ၊ ကိုယ့်ရဲ့လိုအပ်ချက်အရ အဲ့ permissions တွေကို ဘယ်လို manipulate လုပ်ရမလဲဆိုတာကို ပြောသွားပါမယ်။
ကျွန်တော်တို့ရဲ့ system ထဲက directory တစ်ခုခုမှာရှိတဲ့ files တွေကို listing လုပ်ကြည့်ချင်ရင် ls command ကိုသုံးတယ်လို့ ကျွန်တော်တို့သိထားပါတယ်။ အဲ့တော့ ဒီ files တွေနဲ့ directories တွေရဲ့ permissions တွေကိုပါကြည့်ချင်တယ်ဆို ဒီ ls -l ဆိုတဲ့ command လေးနဲ့ကြည့်ကြည့်ရအောင်။
ls -l /home/hhw
ဒီပုံမှာမြင်ရမှာကတော့ ကျွန်တော်ရဲ့ ubuntu-test ဆိုတဲ့ machine ထဲက /home/hhw ဆိုတဲ့ directory အောက်မှာရှိတဲ့ files တွေနဲ့ sub directories တွေရဲ့ permissions တွေပဲဖြစ်ပါတယ်။ Directories တွေကို ခွဲခြားသိဖို့ command ရဲ့ output မှာထိပ်ဆုံး ကိုကြည့်ရင် d ဆိုတာ directory ကိုရည်ညွှန်းပါတယ်။ ရိုးရိုး file ဆိုရင် - symbol လေးနဲ့ပြမှာဖြစ်ပြီး symbolic link ဆိုရင်တော့ l ဆိုတဲ့ symbol လေးရှိနေမှာပါ။ အဲ့နောက်မှာဆက်တွေ့ရမယ့် rwx ဆိုတာတွေကတော့ ဒီ files or directories ရဲ့ permissions တွေပဲ ဖြစ်ပါတယ်။ အောက်မှာအသေးစိပ်ဆက်ပြောပါမယ်။
ဟုတ်ပြီ ကျွန်တော်တို့ ဒီ /home/hhw directory ထဲမှာရှိတဲ့ files တွေနဲ့ sub directories တွေရဲ့ attributes တွေ၊ permissions တွေကိုတော့ကြည့်ပြီးပြီ၊ ဒီ parent directory ကြီးကိုယ်တိုင်ရဲ့ permission တွေ၊ owner တွေကိုကြည့်ချင်တယ်ဆိုရင်ရော
ls -ld /home/hhw
ဆိုပြီးကြည့်လို့ရပါတယ်။ အောက်ပါအတိုင်းမြင်ရမှာပါ။
ဒီ file permissions တွေကိုကြည့်တဲ့အခါမှာ ကျွန်တော်တို့ သုံးပိုင်းခွဲကြည့်ပါမယ်။ ပထမဆုံး rwx ဆိုတဲ့ အပိုင်းကတော့ ဒီ file ရဲ့ owner (user) ရဲ့ permissions ကိုကိုယ်စားပြုပါတယ်။ ဒုတိယ rwx ဆိုတဲ့အပိုင်းကတော့ ဒီ file ရဲ့ group owners ( group ) ရဲ့ permissions ကိုကိုယ်စားပြုပါတယ်။ တတိယ အပိုင်းက r-x လို့တွေ့နေရတဲ့ အပိုင်းကတော့ ဒီ system ထဲမှာရှိနေတဲ့ တစ်ခြား users တွေအကုန် ( others ) ရဲ့ permission ကိုကိုယ်စားပြုပါတယ်။
chmod
ဒီ permissions တွေကို change ချင်တယ်ဆိုရင်တော့ chmod command ကိုသုံးပြီး change နိုင်မှာ ဖြစ်ပါတယ်။ အဲ့မှာမှ ကျွန်တော်တို့ ပုံစံ ၂မျိုးနဲ့ change လို့ရပါတယ်။ ကျွန်တော်တို့ u+rwx, g+rwx ဆိုပြီး symbolic ပုံစံမျိုးနဲ့ change လို့လည်းရပြီး chmod 770 ဆိုပြီး numeric code ပုံစံမျိုး အသုံးပြုပြီးတော့လည်း change လို့ရပါတယ်။ အောက်မှာ symbol တွေရဲ့ ဆိုလိုရင်းနဲ့ သူတို့နဲ့ တူညီတဲ့ numeric value တွေကို ဖော်ပြပေးသွားပါမယ်။
ဘယ်နေရာမှာ ဘယ်လို format နဲ့သုံးမလဲ ဆိုတာကတော့ ကိုယ်သင့်တော်သလို ရွေးချယ်ပြီးသုံးရမှာပါ။
ဥပမာ အနေနဲ့ ကျွန်တော်တို့က ရှိပြီးသား file တစ်ခုကို group နဲ့ other users ကို read and execute permission ထပ်ပေးချင်တယ်ဆိုပါတော့၊ ဒါဆိုရင်
chmod go+rx (file-name)
ဆိုပြီးသုံးလို့ရပါတယ်။
ထိုနည်းတူစွာပဲ ကျွန်တော်တို့က ရှိပြီးသား permission တစ်ခုခုကို ပြန်ရုတ်သိမ်းချင်တယ်ထားပါတော့၊ other users ကို execute permission မပေးချင်ဘူးဆိုရင် ဒီလိုသုံးလို့ရပါတယ်။
chmod o-x (file-name)
ဒါပေမဲ့ file တစ်ခုကို အသစ် create ပြီးကျွန်တော်တို့က file owner နဲ့ group owners တွေကိုတော့ permissions အပြည့်ပေးချင်တယ်၊ others ကိုတော့ ဘာ permissions မှ မပေးချင်ဘူး၊ အဲ့လို တိတိကျကျ သိနေတာမျိုးဆို
chmod 770 (file-name) ဆိုပြီးအလွယ်တစ်ကူသုံးနိုင်ပါတယ်။
chmod u=rwx,g=rwx,o= (file-name) ဆိုတဲ့ command နဲ့ သဘောတရား အတူတူပါပဲ။
နောက်ဥပမာတစ်ခုအနေနဲ့ ကျွန်တော်တို့က script file တစ်ခု create ပြီးပြီ ထားပါတော့၊ အဲ့ file ကို shell ကနေ execute လုပ်နိုင်အောင် execute permission ထည့်ချင်တယ်ဆိုရင်
chmod a+x myscript.sh
ဆိုပြီးထည့်လိုက်လို့ရပါတယ်။ a ဆိုတာ all ကိုကိုယ်စားပြုပြီး ugo+x လို့သုံးတာနဲ့ သဘောတရားတူပါတယ်။
Changing file ownership
ကျွန်တော်တို့က file တစ်ခုရဲ့ owner နဲ့ group owner ကိုပြောင်းချင်တဲ့ အချိန်မှာ chown ဆိုတဲ့ command ကိုအသုံးပြုနိုင်ပါတယ်။ ဒါပေမဲ့ အဲ့လိုပြောင်းဖို့အတွက် ကိုယ်က ဒီ file ရဲ့ owner သို့မဟုတ် super user access ရှိဖို့တော့လိုအပ်ပါတယ်။ ဥပမာအနေနဲ့ ကျွန်တော့်စက်ထဲက hhw ပိုင်တဲ့ file တစ်ခုကို တစ်ခြား user တစ်ယောက်အပိုင်ဖြစ်အောင် ပြောင်းကြည့်ပါမယ်။
ls -l testfile1
sudo chown anna testfile1
ဒီနေ့မှာတော့ Linux file standard permissions တွေအကြောင်းပြောခဲ့တာဖြစ်ပြီး knowledge ရမယ်လို့ မျှော်လင့်ပါတယ်။ နောက်တစ်နေ့မှာတော့ ဒီ user, group, others လို့အုပ်စုသုံးခုခွဲပြီး သက်ဆိုင်ရာ permissions တွေသတ်မှတ်ပေးထားတာထက်ပိုပြီး ဘယ်လို advanced permissions တွေရှိသေးလည်း ဆိုတာကိုဆက်ရေးသွားပါမယ်။
Subscribe to my newsletter
Read articles from Hein Htet Win directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Hein Htet Win
Hein Htet Win
I am a DevOps Engineer from Yangon, Myanmar. I fell in love with automation and CI/CD. I also enjoy using open-source software and regularly contribute to and participate on webinars. In my spare time, I enjoy playing games with my friends in addition to my job.