LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   General (https://www.linuxquestions.org/questions/general-10/)
-   -   Linux file/directory permission question (https://www.linuxquestions.org/questions/general-10/linux-file-directory-permission-question-752244/)

cpthk 09-02-2009 07:25 PM

Linux file/directory permission question
 
Hi:

I read many documentation out there, many seems to be incorrect.
For example this one: http://www.zzee.com/solutions/linux-...k_9_1077830297

It says if I have write permission on directory, I will be able to add, rename, and delete files in the directory. The truth is not. I tested, it really need the execute permission, too, to be able to add, rename, and delete. So many information out there are wrong, this one, too: https://help.ubuntu.com/community/FilePermissions

Another weird thing is, if I have all read, write, execute permission to this directory. Even the files inside only has read permission, I can still edit them no problem. I used vim to edit, and to :w! to save them, and it works. Why is that?

Thanks.

Tinkster 09-02-2009 07:46 PM

Quote:

It says if I have write permission on directory, I will be able to add, rename, and delete files in the directory. The truth is not. I tested, it really need the execute permission, too, to be able to add, rename, and delete.
Please give a specific example? No one here knows what you're seeing/doing,
so it's hard to say why what is going on.

Quote:

Another weird thing is, if I have all read, write, execute permission to this directory. Even the files inside only has read permission, I can still edit them no problem. I used vim to edit, and to :w! to save them, and it works. Why is that?
You're working as root?

joeBuffer 09-02-2009 08:03 PM

What cpthk is saying is true, really. What it says is to cd into the directory you have to have execute permission, but to change/create/remove files from the directory you have to have write permission.
If you have write permission and try to change/create/remove files from the directory without also having execute permission, you can't do it.
Quote:

write
(create or remove files from dir)
w or 2

execute
(cd into directory)
x or 1
---
As far as having read permission only on the file and using vim and :w!, it forces a write. You don't have to use :w! if you have write permission.
When using vim in this situation and editing a file, it will say at the bottom:
Quote:

W10: Warning: Changing a readonly file
When you try to write with :w, it will give the message:
Quote:

E45: 'readonly' option is set (add ! to override)
Then you override it with :w!
That's all you're doing, is overriding it.

Look here:
http://www.tuxfiles.org/linuxhelp/filepermissions.html

cpthk 09-02-2009 11:40 PM

Quote:

Originally Posted by Tinkster (Post 3667530)
Please give a specific example? No one here knows what you're seeing/doing,
so it's hard to say why what is going on.

I already gave example, I gave the website showing I only need write permission to add, rename, delete. But the truth is not.

No, I am not running as root.

Quote:

Originally Posted by joeBuffer (Post 3667546)
Then you override it with :w!
That's all you're doing, is overriding it.

But isn't file system suppose to enforce file security? If I can easily do override, then any virus or spyware could do it too. So you were saying vim ignore the file permission? What is the condition vim could override the permission? I suppose vim shouldn't override the permission in the case that those files really need to be protected.

Wim Sturkenboom 09-02-2009 11:59 PM

You're right that you need execute permission on a directory to be able to do anything in it.

joeBuffer is incorrect, w! will not force a write on a read only file. If you try it, it will give you an error message

The result of w! on a readonly file abc.txt
Code:

abc.txt unwritable

karamarisan 09-03-2009 12:12 AM

My vim will do it fine. And why not? I own the file. vim can chmod write permissions onto it, write to the file, and them chmod them off. Files owned by root... that's another story.

Tinkster 09-03-2009 01:07 AM

Quote:

Originally Posted by cpthk (Post 3667698)
I already gave example, I gave the website showing I only need write permission to add, rename, delete. But the truth is not.

No, I am not running as root.

Well ... if there's no actual question, but just a complaint
about some web-tutorial this thread is going to GENERAL.



Cheers,
Tink

Wim Sturkenboom 09-03-2009 02:28 AM

OK, in my case it's elvis (on Slackware 10.1; vi is symlinked to it), not vim. I always forget about the difference :doh:

The result of :w in vim
Code:

"abc.txt"
E45: 'readonly' option is set (add ! to override)

and the result of :w! in vim
Code:

"abc.txt"
"abc.txt" E212: Can't open file for writing

So there might be a difference between the implementations of vim in different distros or between versions of vim

And the permissions:
Code:

wim@btd-techweb01:~/test$ ls -l
total 9
-rw-r--r--  1 wim develop  0 2009-06-29 12:03 abc\ +\ def.txt
-rw-r--r--  1 wim develop  0 2009-06-29 12:19 abc#.txt
-r--r--r--  1 wim develop 24 2009-09-03 06:48 abc.txt
drwxr-xr-x  2 wim develop 72 2009-08-06 09:35 lq744068/
-rwxr-xr-x  1 wim develop 37 2009-06-29 12:12 myscript.php*
wim@btd-techweb01:~/test$ ls -ld ../test
drwxr-xr-x  3 wim develop 184 2009-09-03 09:17 ../test/
wim@btd-techweb01:~/test$


cpthk 09-03-2009 06:55 PM

I have file permission:
Code:

-r-------- test test file
In my case, vim still allow me to override and write to file. If I do:
Code:

:w
E45: 'readonly' option is set (add ! to override)

I do:
Code:

:w!
"file" 3L, 27C written


joeBuffer 09-03-2009 07:52 PM

Quote:

Originally Posted by karamarisan (Post 3667730)
My vim will do it fine. And why not? I own the file. vim can chmod write permissions onto it, write to the file, and them chmod them off. Files owned by root... that's another story.

I don't know the details, but this is what I've assumed happens.
Code:

joebuffer@ubuntu:~$ cd test
joebuffer@ubuntu:~/test$ touch abc.txt; chmod 0400 abc.txt
joebuffer@ubuntu:~/test$ ls -l
total 0
-r-------- 1 joebuffer joebuffer 0 2009-09-03 17:50 abc.txt
joebuffer@ubuntu:~/test$ vim abc.txt
joebuffer@ubuntu:~/test$ ls -l
total 4
-r-------- 1 joebuffer joebuffer 4 2009-09-03 17:51 abc.txt
joebuffer@ubuntu:~/test$ cat abc.txt
abc

W10: Warning: Changing a readonly file
E45: 'readonly' option is set (add ! to override)
"abc.txt" 1L, 4C written


It must be something they added in more recent versions...

Wim Sturkenboom 09-03-2009 11:46 PM

You can modify vim's behaviour using the W flag in cpoptions

gnashley 09-04-2009 01:32 AM

Keep in mind that the type of filesystem and the mount options(if on a separate partition) will affect your ability to read/write files also.


All times are GMT -5. The time now is 12:47 AM.