Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Out of the two options to change permissions:

  • chmod 777 file.txt
  • chmod a+rwx file.txt

I am writing a document to send out to our customers, detailing that they need to change the file permissions of a certain file. I want to detail it as the most common way of changing file permissions.

Currently is says:

- Set permissions on file.txt as per the example below:
    - chmod 777 /tmp/file.txt

This is just an example, and won't change files to have full permissions for everyone.

share|improve this question

closed as primarily opinion-based by polym, Anthon, Networker, Jenny D, terdon Sep 4 at 14:23

Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise.If this question can be reworded to fit the rules in the help center, please edit the question.

6  
first solution is shorter and more widely used, I never seen the second. –  Archemar Sep 3 at 14:21
1  
setting read, write AND execute permissions for everyone is really no good idea in terms of security. You should use chmod 773 instead. –  Martin Erhardt Sep 3 at 19:34
1  
@MartinErhardt I would normally just use 775 or 755 for executable files only. –  Kevdog777 Sep 4 at 7:49
3  
chmod 777 is like chmod a=rwx, not chmod a+rwx. –  Stéphane Chazelas Sep 4 at 10:32
1  
777 or 666 is simple and much more memorizable than ugo+rwx, a+rwx or ugo+rw which is very confusing as o is ambiguous and can mean for you either owner or others, you choose. So instead making the big mistake, you keep checking man to verify which one is which one, or just use the numbers. –  kenorb Sep 15 at 15:18

4 Answers 4

up vote 16 down vote accepted

Google gives:

chmod 777 is about 3 times more popular.

That said, I prefer using long options in documentation and scripts, because they are self-documenting. If you are following up your instructions with "Run ls -l | grep file.txt and verify permissions", you may want to use chmod a+rwx because that's how ls will display the permissions.

share|improve this answer
    
Thanks for this. I guess that by writing it out in full (alphanumeric) will prevent people from asking what does the 7 mean, etc. –  Kevdog777 Sep 3 at 14:54
    
I think the reason chmod 777 is more popular (as conjetured before seeing your numbers) is simply that you type 2 characters less :) –  Ángel Sep 3 at 15:07
    
If you're into adding tips in your documentation, you can add a tip that chmod 777 is a handy shortcut to achieve the same effect. Your readers would appreciate the educational element in your documentation. 777 is more popular because it's a lot easier and faster to hit 7 three times, but when a new user sees 777 for the first time they may not know what exactly it means. That's why it's a bad choice as primary documentation. But it's definitely worth mentioning as a tip. –  ADTC Sep 3 at 23:54
    
As a tangent, my brother and his friends would use this technique for allowing Scrabble words. They had some threshold for number of Google hits before a word was considered 'real' –  Wayne Werner Sep 4 at 11:09

[I edit to add best practice, following Dotancohen suggestion in his answer. I hope it doesn't make it less clear, and that the good habit is taken]

Important additional information: They are not equivalent.

chmod a+rwx : set the last 3 octals to 777, so it ensure that Owner, Group and Users have the "rwx" set. If there was aditionnal bits in the first octal (setuid, setgid, and/or Sticky bit) it leaves them untouched. Think about it as a binary "or 00777".

chmod 777 : set the rights to 00777, so it ensure Owner, Group and Users have "rwx" set, AND NOTHING MORE. It also make sure the additional bits (setuid, setgid, and/or Sticky bit) are set to 0.

So use the first form, if you just want to make sure to grant access to everyone (and please make double, triple sure that it is required... it opens the door to all sort of security problems, some quite unexpectedly broad in what they allow a malicious user to do)

Use the 777 form if you also want to make sure to reset any setuid/setgid/sticky bit, ie if the files needs to be "00777", which is probably more likely in your case (the file's right is known, and should be : 00777). Here also, make triple sure that it is really needed...

Usually it's best to keep access to owner(and sometimes group) : then use the groups to grant access to some specific users to the file/directory. a+rwx is both easy and usually the wrong way to grant access (of course there are very rare cases when it is the only way...)

http://en.wikipedia.org/wiki/Chmod is a good read as it explains what each number or letter represents (including setuid/setgid/sticky)

share|improve this answer
1  
In addition, chmod a+w (which a+rwx includes) on a suid file is very dangerous. Do I need to elaborate on chmod a+w *? –  Joshua Sep 3 at 19:15
    
What is the point in setting the others permission? If you are logged into the machine as the user, then surely you can just use the users permission? –  Kevdog777 Sep 4 at 7:52
    
@Kevdog777: Others is for people not the owner nor in the group, aka everyone else on the system –  Olivier Dulac Sep 4 at 7:59
1  
@Kevdog777: if only root and the user need access : chmod 00600 (if no need to execute the file) or chmod 00700 (if needs to execute the file -or- it's a directory). or chmod 00400 to add a (tiny, easily overridden) protection against modifying/writing to the file (00500 for a directory). Then others (and people in the group but not the user) can't access the file/dir. (following dotandcohen note, I add the 4th octal in there + a "0" before it: makes no difference for the shell, but helps if you set via perl/C/etc and the 4th octal is a kind of reminder that it exists, and that it is set too) –  Olivier Dulac Sep 4 at 8:04
2  
chmod 777 is like chmod a=rwx. –  Stéphane Chazelas Sep 4 at 10:32

I usually think of the difference being that setting the permissions to 0777 explicitly sets them to 0777. As mentioned earlier, the leading 0 will be inferred if you just type 777. Whereas a+rwx adds read/ write/ execute leaving the setuid/ sticky bit untouched.

Suppose you just want to be sure that a file is executeable, you might use a+x so that you can modify the execution privilege without worrying about or modifying the other permissions. If you used the octal representation, you would need to know what the permissions are currently set to to be sure that you do not modify the permissions in some other way besides what you intended.

share|improve this answer

I would say that giving the numerical values is far more common in "simple peoples guides" such as those produced for users of budget web hosting. However, take care to specify them as octal, not decimal, values:

$ chmod 0777 some_dir

Note the leading 0 in 0777. This means octal.

Note to downvoters: As clarified in the comments, the chmod command does in fact know to pass the directive as octal even if decimal notation is specified. However, not all environments support this, thus it is best practice to get used to specifying it explicitly.

share|improve this answer
    
OK, what does the octal mean? To be honest, I use the numerical values too, but I know other people use the alphanumeric option. –  Kevdog777 Sep 3 at 14:50
9  
chmod does never treat the number as decimal. chmod 777 file and chmod 0777 file are completely equivalent. –  celtschk Sep 3 at 14:51
2  
@Kevdog777: "octal" just means base-8. But you don't need to care about it, as far as usage of the chmod shell command is concerned; you can just think of the three digits as independent from each other, each one telling you one set of permissions. –  celtschk Sep 3 at 14:54
3  
To chmod, the 0 in 0777 actually means “clear the setuid, setgid, and sticky bits”. This is equivalent to 777, as the argument is always padded with leading zeros to four digits. For the same reason, chmod 77 is equivalent to chmod 077. –  Emil Jeřábek Sep 3 at 15:22
    
@EmilJeřábek: actually, chmod 77 is more equivalent to 0077 : it sets all 4 octals to: 0, 0, 7 and 7. (so it clears the "user" bits, but also the "setuid/setgid/sticky" bits) –  Olivier Dulac Sep 3 at 16:35

Not the answer you're looking for? Browse other questions tagged or ask your own question.