whats the difference between chmod 777 and chmod 7777

9

2

I have a professor who insists on always typing chmod 7777, but I was taught that chmod 777 was the proper convention.

I tried them out on the command line and chmod 777 something.txt yeilds

-rwxrwxrwx   1 home  staff    0 May  6 16:47 something.txt

and chmod 7777 something.txt yields

-rwsrwsrwt   1 home  staff    0 May  6 16:47 something.txt

Which changes the executable fields to s, s and t. I understand 777 because it's 111 111 111 in binary, so its just turning on all the fields, but why would I use 7777 and what does it do differently?

Loourr

Posted 2013-05-06T20:54:20.383

Reputation: 325

Related: How does the sticky bit work?

– Scott – 2017-10-29T06:44:20.620

Is there any difference between mode value 0777 and 777 – phuclv – 2018-02-12T09:34:44.713

2

It has to do with the sticky bit. You can check http://en.wikipedia.org/wiki/Sticky_bit

– fedorqui – 2013-05-06T20:58:33.270

Also see http://en.wikipedia.org/wiki/Setuid

– None – 2013-05-06T20:58:46.827

4And as a warning, there are only very specific situations you need to use it. Why your professor would set it normally without explanation is asking for security issues. – None – 2013-05-06T21:00:06.507

Answers

14

In 7777, the first three bits are the setuid, setgid, and sticky flags. These should only be set under very special circumstances. You're correct that 777 is the more appropriate setting (if you want to make the file both world-writable and world-executable).

And unless the file is an executable program or script, or a directory, you usually shouldn't set the x bits. There's not much harm in doing so, though.

Barmar

Posted 2013-05-06T20:54:20.383

Reputation: 1 913

Good explanation. – Chandra Nakka – 2014-07-22T14:20:30.707

What, exactly, do those tags do? When do I want to use the setuid, setgid, and sticky flags? Does using them when they shouldn't be used cause problems? – Aaron Franke – 2016-12-16T21:42:15.170

They have different meanings depending on whether you're setting them on a file or directory, and whether the file is executable or not. Whether they cause problems depends on the specifics. Most of the time they aren't needed. Google them to find out what they do, I'm not going to try to explain all the details here. – Barmar – 2016-12-16T21:46:12.187

1

There is no reason for a sensible professor to insist setting the setuid/gid and sticky bits so perhaps are you confusing 7777 and 0777.

The permissions being stated as an octal number, the proper convention to represent them is to prepend a 0. This is just like when 0x is used to distinguish an hexadecimal number.

Note that chmod doesn't expect the permissions to be expressed in decimal or hexadecimal so this octal prefix is optional.

jlliagre

Posted 2013-05-06T20:54:20.383

Reputation: 12 469

2He was a physics professor so that may have been the issue – Loourr – 2017-10-08T02:16:51.250

@Loourr Well, being a physics professor is not per se an issue ;-) I guess you actually mean that professor was not a computer science one. It might indeed be the reason of the wrong advice. – jlliagre – 2017-10-08T10:17:23.177

0

The leftmost digit is the setuid, setgid, and stickybit digit. The first two set the effective user and group ids of the user opening the file. I don't know what stickybit is.

jhunter_d

Posted 2013-05-06T20:54:20.383

Reputation: 11

-1

The sticky bit is used to tell the operating system to keep the file in RAM as much as possible to reduce reads from disk and reduce latency. This is applied to files that are sued often and needed with high immediacy. Some OS's and software systems ignore it or use other methods to accomplish the same thing. But that is where the sticky name comes from (keep it stuck in memory whenever possible)

unhackable

Posted 2013-05-06T20:54:20.383

Reputation: 1