LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > General
User Name
Password
General This forum is for non-technical general discussion which can include both Linux and non-Linux topics. Have fun!

Notices


Reply
  Search this Thread
Old 09-02-2009, 07:25 PM   #1
cpthk
Member
 
Registered: Aug 2009
Posts: 31

Rep: Reputation: 15
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.
 
Old 09-02-2009, 07:46 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
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?

Last edited by Tinkster; 09-02-2009 at 07:48 PM.
 
Old 09-02-2009, 08:03 PM   #3
joeBuffer
Member
 
Registered: Jul 2009
Distribution: Ubuntu 9.04
Posts: 328

Rep: Reputation: 42
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

Last edited by joeBuffer; 09-02-2009 at 08:09 PM.
 
Old 09-02-2009, 11:40 PM   #4
cpthk
Member
 
Registered: Aug 2009
Posts: 31

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by Tinkster View Post
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 View Post
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.

Last edited by cpthk; 09-02-2009 at 11:46 PM.
 
Old 09-02-2009, 11:59 PM   #5
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Ubuntu 12.04, Antix19.3
Posts: 3,794

Rep: Reputation: 282Reputation: 282Reputation: 282
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

Last edited by Wim Sturkenboom; 09-03-2009 at 12:01 AM.
 
Old 09-03-2009, 12:12 AM   #6
karamarisan
Member
 
Registered: Jul 2009
Location: Illinois, US
Distribution: Fedora 11
Posts: 374

Rep: Reputation: 55
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.
 
Old 09-03-2009, 01:07 AM   #7
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Quote:
Originally Posted by cpthk View Post
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
 
Old 09-03-2009, 02:28 AM   #8
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Ubuntu 12.04, Antix19.3
Posts: 3,794

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

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$
 
Old 09-03-2009, 06:55 PM   #9
cpthk
Member
 
Registered: Aug 2009
Posts: 31

Original Poster
Rep: Reputation: 15
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
 
Old 09-03-2009, 07:52 PM   #10
joeBuffer
Member
 
Registered: Jul 2009
Distribution: Ubuntu 9.04
Posts: 328

Rep: Reputation: 42
Quote:
Originally Posted by karamarisan View Post
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...
 
Old 09-03-2009, 11:46 PM   #11
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Ubuntu 12.04, Antix19.3
Posts: 3,794

Rep: Reputation: 282Reputation: 282Reputation: 282
You can modify vim's behaviour using the W flag in cpoptions
 
Old 09-04-2009, 01:32 AM   #12
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,928

Rep: Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
DISCUSSION: Setting File and Directory Permission in Unix/Linux munawer_hassan LinuxAnswers Discussion 1 03-23-2010 11:40 AM
how do i get permission to move file into directory timalan SUSE / openSUSE 2 08-24-2005 09:25 PM
Useful article: "Linux File & Directory Permission Mistakes" sundialsvcs Linux - Security 1 08-15-2005 11:50 AM
file/directory access permission question correro Linux - General 4 05-22-2003 07:48 PM
Setting File / Directory Permission, with sticky Primetime Linux - Newbie 3 01-06-2003 01:14 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > General

All times are GMT -5. The time now is 04:32 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration