Friday, January 3, 2014

Bash Shell: Permissions ကုိေလ့လာျခင္း….အပိုင္း(၁)

 

 

 ဒီပုိ႔ကေတာ့ ေအာက္ပါ Command ေတြကုိ အဓိကထားျပီးရွင္းျပေပးသြားမွာျဖစ္ပါတယ္။

  • chmod – modify file access rights
  • su – temporarily become the superuser
  • chown – change file ownership
  • chgrp – change a file’s group ownership

File permissions


  • System မွာပါ၀င္တဲ့ File ႏွင့္ Directory တစ္ခုစီသည္ File တစ္ခုရဲ့ Owner ၊ User ေတြနဲ႔ ဆက္စပ္ေနေသာ Group ရဲ့ Member ေတြ ႏွင့္ အျခားေသာလူတုိင္းအတြက္ “Access Right” ကုိသတ္မွတ္ေပးထားပါတယ္။ “Right” ေတြကုိ “Read” ၊ “Write” ႏွင့္ “Execute” ဆုိျပီး သတ္မွတ္ႏုိင္ပါတယ္။

  • File တစ္ခုရဲ့ Permission ကုိၾကည့္ခ်င္တယ္ဆိုရင္ က်ေနာ္တုိ႔အေနျဖင့္ ေအာက္ပါအတုိင္း “ls” Command ကုိသုံးႏုိင္ပါတယ္။

ls -l some_file
 -rw-rw-r-- 1 me me 1097374 Jan 19 16:48 some_file

  • ဒီ Command ရဲ့ Result ေတြကုိစစ္ေဆးမယ္ဆိုရင္အမ်ားၾကီးဆုံးျဖတ္ႏုိင္ပါတယ္။

  • File “some_file” ကုိ “me” ဆုိတဲ့ User ကို ပုိင္ဆိုင္ပါတယ္။
  • User “me” မွ Read and Write လုပ္ပုိင္ခြင့္ရွိေနပါတယ္။
  • ထုိ file ကုိ  “me” ဆုိတဲ့ Group ကို ပုိင္ဆုိင္ပါတယ္။
  • me” Group ရဲ့ Member ေတြလဲ ဒီ File ကုိ Read and Write လုပ္ႏုိင္ပါတယ္။
  • အျခား User ေတြကေတာ့ Read ပဲလုပ္ႏုိင္ပါတယ္။

  • ေနာက္ဥပမာတစ္ခုကုိၾကည့္ရေအာင္။ /bin directory ထဲမွာရွိတဲ့ bash program ကုိၾကည့္မွာျဖစ္ပါတယ္။

ls -l /bin/bash
Terminal မွာ ေအာက္ပါပုံစံအတုိင္းျပေပးပါလိမ့္မယ္။
-rwxr-xr-x 1 root root 916692 2011-05-18 16:24 /bin/bash

  • ဒီေနရာမွာေလ့လာၾကည့္မယ္ဆိုရင္…

  • File “/bin/bash” ကုိ “Root” က ပုိင္ဆုိင္ပါတယ္။
  • SuperUser မွာ ဒီဖုိင္ကုိ “read, write, and execute” လုပ္ပုိင္ခြင့္ရွိပါတယ္။
  • ဒီဖုိင္ကုိ “root” Grpup က ပုိင္ဆုိင္ပါတယ္။
  • “root” Grpup ရဲ့ Member ေတြလဲ ဒီဖုိင္ကုိ “read, write, and execute” လုပ္ပုိင္ခြင့္ရွိပါတယ္။
  • အျခား User ေတြ မွာေတာ့ “Read and Execute” ပဲလုပ္ႏုိင္ပါတယ္။

  • ေအာက္ပါ Diagram မွာ ေလ့လာၾကည့္ပါ။
permissions diagram

chmod


  • “Chmod” ကုိေတာ့ File or Directory တစ္ခုရဲ့ Permission ကုိ ေျပာင္းလဲရန္ အသုံးျပဳပါတယ္။ ၄င္းကုိ သံုးရန္ မိမိဆႏၵရွိေသာ Permission Setting ေတြႏွင့္ Modify လုပ္ခ်င္ေသာ File or File မ်ားကုိ Specify လုပ္ထားႏုိင္ပါတယ္။ Permission ကုိ Specify လုပ္ရန္ နည္းလမ္းႏွစ္မ်ဳိးရွိပါတယ္။ ဒါေပမယ့္ က်ေနာ့္အေနျဖင့္ တစ္ခုကုိပဲဒီမွာ တင္ျပေပးပါမယ္။

  • ေအာက္ပါတုိ႔ကိုေလ့လာၾကည့္ပါ။

rwx rwx rwx = 111 111 111 rw- rw- rw- = 110 110 110 rwx --- --- = 111 000 000 and so on... 

rwx = 111 in binary = 7 rw- = 110 in binary = 6 r-x = 101 in binary = 5 r-- = 100 in binary = 4 

  • Digit တစ္မ်ဳိးတည္းျဖင့္ Permission သုံးမ်ဳိးကုိ ကုိယ္စားျပဳေစခ်င္ရင္ Possible Permision ေတြကုိ ေဖာ္ျပရန္ လြယ္ကူရိုးရွင္းေသာ နည္းလမ္းရွိပါတယ္။ မိမိအေနျဖင့္ some_file ဆုိတဲ့ဖုိင္ တစ္ခုကုိ Owner အတြက္ “Read and Write” Permission ကုိသတ္မွတ္ေပးျပီး အျခား User ေတြကုိ ကန္႔သတ္ထားခ်င္တယ္ဆိုရင္…..

chmod 600 some_file

  • ေအာက္ပါ Table of Number ကေတာ့ Commom Setting ေတြအတြက္ ျပေပးထားပါတယ္။
  • Here is a table of numbers that covers all the common settings. The ones beginning with “7″ နဲ႔စထားတဲ့ Number ေတြကေတာ့ ‘execute” လုပ္ႏုိင္ေသာ Program မ်ားျဖင့္သုံးပါတယ္။ က်န္တဲ့အရာေတြကေတာ့ အျခား ဖုိင္အမ်ဳိးအစားေတြအတြက္သုံးပါတယ္။

Value Meaning
777 (rwxrwxrwx) No restrictions on permissions. Anybody may do anything. Generally not a desirable setting.
755 (rwxr-xr-x) The file’s owner may read, write, and execute the file. All others may read and execute the file. This setting is common for programs that are used by all users.
700 (rwx——) The file’s owner may read, write, and execute the file. Nobody else has any rights. This setting is useful for programs that only the owner may use and must be kept private from others.
666 (rw-rw-rw-) All users may read and write the file.
644 (rw-r–r–) The owner may read and write a file, while all others may only read the file. A common setting for data files that everybody may read, but only the owner may change.
600 (rw——-) The owner may read and write a file. All others have no rights. A common setting for data files that the owner wants to keep private.

No comments:

Post a Comment