• Downloads
  • ! Read Me !
  • Μαθήματα
  • Φοιτητικά
  • Τεχνικά Θέματα
  • Συζητήσεις
  • Happy Hour!
  • About THMMY.gr
 V  < 
Search:  
Welcome, Guest. Please login or register.
June 18, 2025, 01:38:31 am

Login with username, password and session length
Links
  Thmmy.gr portal
   Forum
   Downloads
   Ενεργ. Λογαριασμού
   Επικοινωνία
  
  Χρήσιμα links
   Σελίδα τμήματος
   Βιβλιοθήκη Τμήματος
   Elearning
   Φοιτητικά fora
   Πρόγραμμα Λέσχης
   Πρακτική Άσκηση
   Ηλεκτρονική Εξυπηρέτηση Φοιτητών
   Διανομή Συγγραμμάτων
   Ψηφιακό Καταθετήριο Διπλωματικών
   Πληροφορίες Καθηγητών
   Instagram @thmmy.gr
   mTHMMY
  
  Φοιτητικές Ομάδες
   ACM
   Aristurtle
   ART
   ASAT
   BEAM
   BEST Thessaloniki
   EESTEC LC Thessaloniki
   EΜΒ Auth
   IAESTE Thessaloniki
   IEEE φοιτητικό παράρτημα ΑΠΘ
   SpaceDot
   VROOM
   Panther
  
Πίνακας Ελέγχου
Welcome, Guest. Please login or register.
June 18, 2025, 01:38:31 am

Login with username, password and session length

Αναζήτηση

Google

THMMY.gr Web
Πρόσφατα
Πρακτική Άσκηση ΤΗΜΜΥ 201...
by chris_p30
[Today at 00:45:33]

[Μεταφορά και Διανομή ΗΕ]...
by Nikos_313
[Today at 00:10:29]

Ισραήλ - Ιράν: Πόλεμος στ...
by Katarameno
[June 17, 2025, 21:32:50 pm]

[Ψηφιακά Ολοκληρωμένα Κυκ...
by tzortzis
[June 17, 2025, 21:25:42 pm]

[Εφ.Θερμοδυναμική] Γενικέ...
by PAPARI69
[June 17, 2025, 20:59:13 pm]

[Γραφική] Λυμένα θέματα
by okanpala
[June 17, 2025, 18:56:22 pm]

Τι ακούτε αυτήν τη στιγμή...
by Katarameno
[June 17, 2025, 14:25:00 pm]

Αντικατάστασης πυκνωτή σε...
by george14
[June 17, 2025, 13:58:20 pm]

Πότε θα βγει το μάθημα; -...
by tzortzis
[June 17, 2025, 13:19:53 pm]

Αποτελέσματα Εξεταστικής ...
by george14
[June 17, 2025, 12:08:25 pm]

[ΨEE] Γενικές απορίες και...
by Juror8
[June 17, 2025, 12:06:57 pm]

[Οργάνωση Υπολογιστών] Γε...
by RAFI
[June 16, 2025, 22:46:54 pm]

[Σ.Π.Η.Ε.] Γενικές απορίε...
by Nikos_313
[June 16, 2025, 19:49:00 pm]

[ΘΤΠΑ] Γενικές απορίες κα...
by Nikos_313
[June 16, 2025, 16:56:56 pm]

[Αρχές Οικονομίας] Να επι...
by _Trob
[June 16, 2025, 13:28:21 pm]

[Σ.Α.Π.Γ.] Εργασία 2025
by Nikos_313
[June 16, 2025, 12:13:45 pm]

[Διανεμημένη Παραγωγή] Γε...
by Διάλεξις
[June 16, 2025, 01:56:37 am]

[Σ.Π.Η.Ε.] Παλιά θέματα -...
by nmpampal
[June 15, 2025, 06:43:15 am]

Το thmmy.gr στο instagram...
by Mr Watson
[June 15, 2025, 00:50:23 am]

[Λογισμός ΙΙ] Απορίες σε...
by el mariachi
[June 14, 2025, 20:47:07 pm]
Στατιστικά
Members
Total Members: 9961
Latest: Poli
Stats
Total Posts: 1426704
Total Topics: 31710
Online Today: 208
Online Ever: 2093
(April 17, 2025, 08:47:49 am)
Users Online
Users: 37
Guests: 175
Total: 212
Spyridon01101
ligditsa
BlackBeard
spoun
Theislander
kostas.de
evitzv
elischat
Η ΤΡΑΠΟΥΛΑ ΤΟΥ ΠΑΠΠΟΥ ΜΟΥ
rafail zisiadis
d0xa
thomasdt
evax
Stelios V.
KZerenidis
kmargaritis
George Hadjilyras
dimchin
Giannis Masterio
giorgosss03
ZontanosThrylos
Tsn
athena_apo
miltan8
marwt
ismini.h
thpanousis
Elenit
tinidou
stelinas
tasos gourd
Captain
Εμφάνιση

Νέα για πρωτοετείς
Είσαι πρωτοετής;... Καλώς ήρθες! Μπορείς να βρεις πληροφορίες εδώ. Βοήθεια για τους καινούργιους μέσω χάρτη.
Κατεβάστε εδώ το Android Application για εύκολη πρόσβαση στο forum.
Ανεβάζετε τα θέματα των εξετάσεων στον τομέα Downloads με προσοχή στα ονόματα των αρχείων!

Νέα!
Πρόγραμμα Χειμερινής Εξεταστικής 2024-2025
THMMY.gr > Forum > Ηλεκτρονικοί Υπολογιστές και Τεχνικά Θέματα > Περί Υπολογιστών... > Software > Linux / Unix (Moderators: chatzikys, PolarBear) > Understanding UNIX permissions and chmod
0 Members and 1 Guest are viewing this topic.
Pages: [1] Go Down Print
Author Topic: Understanding UNIX permissions and chmod  (Read 850 times)
aliakmwn
Guest
Understanding UNIX permissions and chmod
« on: September 25, 2005, 13:38:04 pm »

Understanding UNIX permissions and chmod

This ius a topic that has been beaten to death both in books and on-line. For some reason, it seems that it is one of the most common misunderstandings that people have to face when learning how to write and/or configure their first cgi programs. This tutorial aims to clarify the concepts involved. Note that we will be referring to UNIX in a generic sense in this article. Most of what we are going to discuss here applies to all UNIX flavours. (such as Linux, SVR4, BSD etc.) It is also a good idea to type man chmod to check for the specific details on your system, too.


Users

A UNIX system serves many users. Users are an abstraction that denotes a logical entity for assignment of ownership and operation privileges over the system. A user may correspond to a real-world person, but also a type of system operation. So, in my system, I have user 'nick' that corresponds to me, but I also have user 'www' which corresponds to the privileges necessary to operate the local webserver. UNIX doesn't care about what the user means for me. It just knows what belongs to any given user and what each user is allowed to do with any given thing (file, program, device, etc) on the system. UNIX identifies each user by a User ID (UID) and the username (or login) such as 'nick' and 'www' is just an alias to the UID that makes humans more comfortable.


Groups

Users can be organized in groups. A user may belong to one or more groups of users. The concept of groups serves the purpose of assigning sets of privileges for a given resource and sharing them among many users that need to have them. (perhaps because they are all members of a project working team and they all need access to some common project files) So, on my system user 'nick' and user 'www' both belong to the group 'perlfect'. This way, they can have some shared privileges over the files for this site. User 'nick' needs them to edit the site, and user 'www' needs them to manage the webserver that will be publishing the site.


Ownership

Every file in UNIX has an owner user and an owner group. So, for any file in the system, user 'nick' may have one of the following ownership relations:

nick owns the file, i.e. the file's owner is 'nick'.
nick is a member of the group that owns the file, i.e. the file's owner group is 'perlfect'.
nick is neither the owner, nor belonging to the group that owns the file

Permissions

Every file on the system has associated with it a set of permissions. Permissions tell UNIX what can be done with that file and by whom. There are three things you can (or can't) do with a given file:

read it,
write (modify) it and
execute it.
Unix permissions specify which of the above operations can be performed for any ownership relation with respect to the file. In simpler terms, what can the owner do, what can the owner group do, and what can everybody else do with the file. For any given ownership relation, we need three bits to specify access permissions: the first to denote read (r) access, the second to denote (w) access and the third to denote execute (x) access. We have three ownership relations: 'owner', 'group' and 'all' so we need a triplet for each, resulting in nine bits. Each bit can be set or clear. (not set) We mark a set bit by it's corresponding operation letter (r, w or x) and a clear bit by a dash (-) and put them all on a row. An example might be rwxr-xr-x.What this means is that the owner can do anything with the file, but group owners and the rest of the world can only read or execute it. Usually in UNIX there is also another bit that precedes this 9-bit pattern. You do not need to know about it, at least for the time being.
So if you try ls -l on the command prompt you will get something like the following:

[nick@thekla src]$ ls -l
-rwxr-xr-x   1 nick     users          382 Jan 19 11:49 bscoped.pl
drwxr-xr-x   3 nick     users         1024 Jan 19 11:19 lib/
-rwxr-xr-x   1 nick     users         1874 Jan 19 10:23 socktest.pl
   
The first column here shows the permission bit pattern for each file. The third column shows the owner, and the fourth column shows the owner group. By the time, the information provided by ls -l should be enough for you to figure out what each user of the system can do with any of the files in the directory.


Directories

Another interesting thing to note is that lib/ which is a directory has permissions, too. Permissions take a different meaning for directories. Here's what they mean:

read determines if a user can view the directory's contents, i.e. do ls in it.
write determines if a user can create new files or delete file in the directory. (Note here that this essentially means that a user with write access toa directory can delete files in the directory even if he/she doesn't have write permissions for the file! So be careful with this.)
execute determines if the user can cd into the directory.

chmod

To set/modify a file's permissions you need to use the chmod program. Of course, only the owner of a file may use chmod to alter a file's permissions. chmod has the following syntax: chmod [options] mode file(s)

The 'mode' part specifies the new permissions for the file(s) that follow as arguments. A mode specifies which user's permissions should be changed, and afterwards which access types should be changed. Let's say for example:

chmod a-x socktest.pl
   
This means that the execute bit should be cleared (-) for all users. (owner, group and the rest of the world) The permissions start with a letter specifying what users should be affected by the change, this might be any of the following:
u the owner user
g the owner group
o others (neither u, nor g)
a all users
This is followed by a change instruction which consists of a +(set bit) or -(clear bit) and the letter corresponding to the bit that should be changed.
Let's see some examples:

$ ls -l socktest.pl
-rwxr-xr-x   1 nick     users         1874 Jan 19 10:23 socktest.pl*

$ chmod a-x socktest.pl
$ ls -l socktest.pl
-rw-r--r--   1 nick     users         1874 Jan 19 10:23 socktest.pl

$ chmod g+w socktest.pl
$ ls -l socktest.pl
-rw-rw-r--   1 nick     users         1874 Jan 19 10:23 socktest.pl

$ chmod ug+x socktest.pl
$ ls -l socktest.pl
-rwxrwxr--   1 nick     users         1874 Jan 19 10:23 socktest.pl*

$ chmod ug-wx socktest.pl
$ ls -l socktest.pl
-r--r--r--   1 nick     users         1874 Jan 19 10:23 socktest.pl
   

Strange numbers...

You might have encountered things like chmod 755 somefile and of course you will be wondering what this is. The thing is, that you can change the entire permission pattern of a file in one go using one number like the one in this example. Every mode has a corresponding code number, and as we shall see there is a very simple way to figure out what number corresponds to any mode.

Every one of the three digits on the mode number corresponds to one of the three permission triplets. (u, g and o) Eve
ry permission bit in a triplet corresponds to a value: 4 for r, 2 for w, 1 for x. If the permission bit you add this value to the number of the permission triplet. If it is cleared, then you add nothing. (Some of you might notice that in fact, the number for a triplet is the octal value corresponding to the three-bit pattern - if you don't know what an octal value is, it doesn't really matter, just follow the intstructions) So if a file has rwxr-xr-x permissions we do the following calculation:

Triplet for u: rwx => 4 + 2 + 1 = 7
Triplet for g: r-x => 4 + 0 + 1 = 5
Tripler for o: r-x => 4 + 0 + 1 = 5
Which makes : 755

So, 755 is a terse way to say 'I don't mind if other people read or run this file, but only I should be able to modify it' and 777 means 'everyone has full access to this file'


Further reading...

It is a good idea to take a look at the manual page for chmod (you can do this with man chmod) where you will find out more details and options on how to set permissions, plus some other kinds of permissions that we avoided to discuss here for the sake of simplicity and clarity.

http://www.perlfect.com/articles/chmod.shtml
Logged
michaelidesc
Guest
Re: Understanding UNIX permissions and chmod
« Reply #1 on: September 25, 2005, 17:01:13 pm »

Θα κάνω μια επισήμανση επειδή έχω παρατηρήσει πως αρκετοί που δεν γνωρίζουν καλά το shell και πώς λειτουργεί, δυσκολεύονται να καταλάβουν τη διαφορά του +r με το +x. Τι θα πει τελικά να μπορείς να διαβάσεις ένα αρχείο αλλά να μην μπορείς να το εκτελέσεις?

r - μπορεί να διαβαστεί το περιεχόμενο ενός αρχείου εκτυπώνοντάς το σε οποιαδήποτε συσκευή εξόδου
x - το αρχείο μπορεί να εκτελεστεί ως ακολουθία εντολών ενός προεπιλεγμένου shell, ή ως δυαδικό

Επίσης, μπορείτε να δείτε σε ποια groups ανήκει το account με το οποίο είστε συνδεδεμένοι, χρησιμοποιώντας την εντολή "id".

Aliakmwn, πολύ καλό το howto, σύντομο και περιεκτικό. Αυτά, ελπίζω να βοήθησα λίγο κι εγώ.
Logged
chggr005
Αbsolute ΤΗΜΜΥ.gr
*******
Gender: Male
Posts: 2566


Free ...as a bird (Beatles)


View Profile
Re: Understanding UNIX permissions and chmod
« Reply #2 on: September 27, 2005, 08:32:54 am »

Σωστός ο συνάδελφος παραπάνω και μπράβο στον Αλιάκμων για το How to  που παρέθεσε! Αν και δεν το περίμενα διότι όπως όλοι θα ξέρετε είναι τρελός με τα Mac...
Απλά κι εγώ θα ήθελα να κάνω μιία επισύμανση σχετικά με το +x. Το να μπορεί να εκτελεστεί ένα αρχείο ως πρόγραμμα σημαίνει πως ο υπολογιστής έχει την άδεια να "δει" το αρχείο ως binary και όχι σαν αρχείο κειμένου πχ. Κατά τα άλλα με κάλυψε ο συνάδελφος michaelidesc
Logged

Goodbye to you, my trusted friend.
We've known each other since we were nine or ten.
Together we 've  climbed hills or trees.
Learned of love and ABC's,
skinned our hearts and skinned our knees.

Goodbye my friend, it's hard to die,
when all the birds are singing in the sky,
Now that the spring is in the air.
Ο λογαριασμός έχει παραβιαστεί, μην ανοίξετε το link. are everywhere.
When you see them I'll be there.

We had joy, we had fun, we had seasons in the sun.
But the hills that we climbed
were just seasons out of time.

Terry Jacks - Seasons In The Sun


Οι πρωτοετείς φοιτητές μπορούν να ενημερωθούν για τον Σύλλογο Φοιτητών Ηλεκτρολόγων Μηχανολόγων Μηχανικών από εδώ:  Σύλλογος Φοιτητών
Pages: [1] Go Up Print
Jump to:  

Powered by SMF | SMF © 2006-2009, Simple Machines LLC
Scribbles2 | TinyPortal © Bloc | XHTML | CSS
Loading...