Linux newbie here, working on Debian Jessie.
Why does chmod u+w not make a file writeable for its owner?
I have run:
sudo chmod u+w /var/log/myapp/gunicorn-error.logBut now if I list the permissions on the file, it still doesn’t seem to be writeable:
ls -al /var/log/myapp/
total 52
drwxr-xr-x 2 opuser webapps 4096 Sep 1 11:08 .
drwxr-xr-x 10 root root 4096 Sep 1 11:24 ..
-rw-r--r-- 1 opuser webapps 0 Aug 23 07:11 gunicorn-access.log
-rw-r--r-- 1 opuser webapps 38639 Sep 1 11:15 gunicorn-error.logWhat am I doing wrong?
41 Answer
Your presented command and related output seem fine; not too sure what you believe is going wrong. You simply issued this chmod command via symbolic mode:
sudo chmod u+w /var/log/myapp/gunicorn-error.logAnd then this is the result:
-rw-r--r-- 1 opuser webapps 38639 Sep 1 11:15 gunicorn-error.logFrom left to right
- The first
rw-is for the user/owner of the file. - The next
r--indicates group permissions. - The final
r--is permissions for others.
So knowing that, your chmod u+w succeeded because the user/owner has rw- permissions.
That said, if somehow your concern is about the group and other permissions, changing the permissions for the user/owner via symbolic mode does not negate existing permissions for the group and other permissions.
If you somehow want to set read and write for a user/owner but negate permissions for the group and others, you need to run a chmod with an absolute (octal) mode setting like this:
sudo chmod 600 /var/log/myapp/gunicorn-error.logWhich would result in permissions like this:
-rw------- 1 opuser webapps 38639 Sep 1 11:15 gunicorn-error.logWhile harder to remember for most casual users, the main benefit of the absolute (octal) mode method is you can set multiple aspects of permissions in one command.
In contrast, symbolic mode makes setting permissions easier to read and remember, but you might need to issue a few symbolic mode commands in a row to achieve the same final result the absolute (octal) mode can achieve in one command.