Jump to content

file permissions


baudolino
 Share

Recommended Posts

[baudolino]$ ls -l

total 4

-rw-r--r--    1 root     root            8 Nov  4 19:48  cannotDELETEme

[baudolino]$ whoami

baudolino

[baudolino]$ groups

baudolino graal

[baudolino]$ rm cannotDELETEme 

rm: remove write-protected regular file `cannotDELETEme'? y

[baudolino]$ ls -l

total 0

[baudolino]$

Since I am not root and I do not belong to group root, my permissions regarding the file cannotDELETEme are r---. How come am I allowed to delete the file?

Link to comment
Share on other sites

Let's talk about permissions, files, and directories.

 

If you have the 'r' right for a file, then you can view its content.

If you have the 'w' right for a file, then you can modify its content.

If you have the 'x' right for a file, then you can execute the file.

 

If you have the 'r' right for a directory, then you can view its content (view what files are there).

If you have the 'w' right for a directory, then you can modify its content (add or remove files).

If you have the 'x' right for a directory, then you can enter the directory, and try to go further in it (nested directories and files).

 

You can remove any file you don't own in a directory you have the right to write in, eg a file created by root in your home directory.

 

Yves.

Link to comment
Share on other sites

Hey Yves - I am pretty certain that when I, as root, create something in /home/static, static can't delete it. (Maybe I'm wrong, but I seem to remember..)

 

This could be a problem with userid's. If baudolino has the same uid as root this will happen.

 

PS Newbies take note: The original post is very neat and easy to follow. Excellent structure - makes it easier for us to help ;O)

Link to comment
Share on other sites

Hey Yves - I am pretty certain that when I, as root, create something in /home/static, static can't delete it. (Maybe I'm wrong, but I seem to remember..)

 

This could be a problem with userid's. If baudolino has the same uid as root this will happen.

 

PS Newbies take note: The original post is very neat and easy to follow. Excellent structure - makes it easier for us to help ;O)

 

I've performed such test on my own machine.

 

[alex@linux alex]$ ls -l somefile

-rw-r--r-- 1 root root 0 Nov 6 17:10 somefile

[alex@linux alex]$ rm somefile

rm: remove write-protected regular empty file `somefile'? y

[alex@linux alex]$ ls -l somefile

ls: somefile: No such file or directory

[alex@linux alex]$ id

uid=501(alex)

 

You're surely wrong :-) . The file was created by root and nevertheless a regular user succeeded to delete it. Pure issue of directory permissions.

Link to comment
Share on other sites

Thanks! I understand now why I was able to delete the file.

It looks like permissions are not as straightforward as I thought. Here is another example:

 

[baudolino]$ pwd

/home/baudolino/testarea

[baudolino]$ id

uid=501(baudolino) gid=501(baudolino) groups=501(baudolino),500(graal)

[baudolino]$ ls

ls: .: Permission denied

[baudolino]$ su

Password: 

[root]# ls -la

total 12

d-w-r-xr--    2 baudolino    baudolino        4096 Nov  6 23:05 ./

drwxr-xr-x    4 baudolino    baudolino        4096 Nov  6 23:08 ../

-rw-r--r--    1 baudolino    baudolino           8 Nov  6 22:16 a

[root]# exit

exit

[baudolino]$ rm a

rm: cannot lstat `a': Permission denied

[baudolino]$ touch b

touch: creating `b': Permission denied

[baudolino]$ cat >> a

bash: a: Permission denied

[baudolino]$

As you can see, I have w permission to both the testarea directory and the a file. I can not write to or modify the file a. I can not create another file in the testarea directory.

 

From my experiments, it looks like I need either -wx or rwx in the testarea directory to remove, modify the a file. I need the same permissions to create a new file in testarea.

 

I wonder about the meaning of r, w, and x for a link, a pipe, a character device or a block device. I will do some experiments tonight on this, but let me know if you already know it!

 

Thanks again!

Link to comment
Share on other sites

You're surely wrong :-) . The file was created by root and nevertheless a regular user succeeded to delete it. Pure issue of directory permissions.
Well Sorrrryy! I did mention I could have been wrong... ;)

 

You learn something everyday.

Link to comment
Share on other sites

I looked in there, but I could not find anything regarding the meaning of the permissions for links, pipes, character devices, block devices or sockets. If you know a specific web link about this topic, please post the exact address.

 

In the meanwhile, if somebody is interested, here is what I found out about permissions for links and pipes.

Here is one (long and successful) experiment:

 

[baudolino]$ id

uid=501(baudolino) gid=501(baudolino) groups=501(baudolino),500(graal)

[baudolino]$ ls -li

total 4

224926 -rwxr--r--    1 baudolino    baudolino           4 Nov  7 23:56 a

[baudolino]$ cat a

abc

[baudolino]$ cat >>a <<"EOF"

> def

> EOF

[baudolino]$ cat a

abc

def

[baudolino]$ ln -s a b

[baudolino]$ ln a c

[baudolino]$ ls -li

total 8

224926 -rwxr--r--    2 baudolino    baudolino           8 Nov  7 23:57 a

224931 lrwxrwxrwx    1 baudolino    baudolino           1 Nov  7 23:57 b -> a

224926 -rwxr--r--    2 baudolino    baudolino           8 Nov  7 23:57 c

[baudolino]$ cat b

abc

def

[baudolino]$ cat c

abc

def

[baudolino]$ chmod u=r c

[baudolino]$ ls -li

total 8

224926 -r--r--r--    2 baudolino    baudolino           8 Nov  7 23:57 a

224931 lrwxrwxrwx    1 baudolino    baudolino           1 Nov  7 23:57 b -> a

224926 -r--r--r--    2 baudolino    baudolino           8 Nov  7 23:57 c

[baudolino]$ cat b

abc

def

[baudolino]$ cat c

abc

def

[baudolino]$ cat >>b <<"EOF"

> xxx

> EOF

bash: b: Permission denied

[baudolino]$ cat >>c <<"EOF"

> yyy

> EOF

bash: c: Permission denied

[baudolino]$ cat b

abc

def

[baudolino]$ cat c

abc

def

[baudolino]$ chmod u=w b

[baudolino]$ ls -li

total 8

224926 --w-r--r--    2 baudolino    baudolino           8 Nov  7 23:57 a

224931 lrwxrwxrwx    1 baudolino    baudolino           1 Nov  7 23:57 b -> a

224926 --w-r--r--    2 baudolino    baudolino           8 Nov  7 23:57 c

[baudolino]$ cat >>b <<"EOF"

> 123

> EOF

[baudolino]$ cat b

cat: b: Permission denied

[baudolino]$ cat >>c <<"EOF"

> 456

> EOF

[baudolino]$ cat c

cat: c: Permission denied

[baudolino]$ chmod u=rwx b

[baudolino]$ ls -li

total 8

224926 -rwxr--r--    2 baudolino    baudolino          16 Nov  8 00:01 a

224931 lrwxrwxrwx    1 baudolino    baudolino           1 Nov  7 23:57 b -> a

224926 -rwxr--r--    2 baudolino    baudolino          16 Nov  8 00:01 c

[baudolino]$ cat b

abc

def

123

456

[baudolino]$

 

1. No mater what I tried, the permissionsof the soft link (B) are always lrwxrwxrwx. Changing the permission of a soft link changes the permission of the target (a).

2. The hard links (a and c) have always the same permissions.

3. The permissions of the soft link (B) are given not by its own permissions (which seem always to be lrwxrwxrwx), but on the permissions of the target(a).

 

Does anybody know how to change the permissions of a soft link (b, in the example above) without changing the permissions of the target (a, in the example above)? The example below shows that it possible, but I don't know how.

 

 

 

[baudolino]$ ls -l /dev/modem

lr-xr-xr-x    1 root     root            5 Nov  7 17:17 /dev/modem ->tts/4

[baudolino]$ ls -l /dev/tts/4

crw-rw----    1 baudolino    tty        4,  68 Nov  7 23:10 /dev/tts/4

[baudolino]$

 

Regarding the permissions of pipes, the r right means that you can put new stuff in the pipe or you can completely change the content of the pipe and the w right means that you can take out all the stuff from the pipe. What I don't know is what is the meaning of the x right for a pipe (if there is a meaning).

 

Sorry for the long post, but I thought somebody might find it interesting, just like I did.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...