You are not logged in.

#1 2008-04-27 11:33:14

faw
Member
Registered: 2007-06-09
Posts: 19

[Solved] File permissions and ownerships

Hi Archers,

I am getting stumped with this one so need some help.

Over the space of about 6 months I have converted/backed up  all of my CDs files to both Flac and Ogg Vorbis files. The CDs are put away where they can't be nicked by mates or scratched by me. As it's taken a bit of work to back them all up I want to make sure I can't accidentally delete them so I want to change the owner of the files to root so that it has to be a conscious decision to su into root to move files or add files to the directory. So worried am I that I don't know what I am doing in regards to file permissions and ownerships that I decided to create a test file to make sure I get it right first. So I created file 'test', made sure permissions were read and write for me and read only for everybody else by 'chmod 644 test', and then changed ownership from me to root via 'chown root test'. End result is that the file now looks like this:

faw@localhost $ ls -l                                     
-rw-r--r-- 1 root users     5 2008-04-27 20:16 test

Now, if I open the file in nano as the normal user faw, it lets me which is good as I have read access. If it try to amend it and save it won't let me, I get [ Error writing test.txt: Permission denied ], this is also good as I am not supposed to have write access, right?

But if I try to rm the file on the command line while still user faw, well, it actually lets me. It does check if I want to the delete the file as you can see, and if I say yes, it lets me. I don't think it should actually let me.

faw@localhost $ rm test                                   
rm: remove write-protected regular file `test'? y

If I try to delete the file in Thunar it lets me as well, without checking.

What is letting me delete a file that isn't owned by my user, and doesn't have write access assigned to my group? Am I understanding ownerships correctly or am I missing something here? The only thing I can think of is that I have somehow given my normal user faw superuser status somehow. I have added a few things to visudo to get things like shutdown in XFCE running, could I have screwed it up somehow?

Not only am I worried that I could lose my music files, but if I can delete a file owned by root, one day I might make a mistake and lose my system too...

Any ideas or guidance?

Thanks,

Last edited by faw (2008-04-27 14:20:02)

Offline

#2 2008-04-27 12:04:28

moljac024
Member
From: Serbia
Registered: 2008-01-29
Posts: 2,676

Re: [Solved] File permissions and ownerships

Were you trying to change permissions with chown (which is for change owner ? The right command for changing permissions is chmod

So try this :

chmod 644 test

The day Microsoft makes a product that doesn't suck, is the day they make a vacuum cleaner.
--------------------------------------------------------------------------------------------------------------
But if they tell you that I've lost my mind, maybe it's not gone just a little hard to find...

Offline

#3 2008-04-27 12:28:18

faw
Member
Registered: 2007-06-09
Posts: 19

Re: [Solved] File permissions and ownerships

Yes I did use chmod, sorry, that was a typo in my post (thanks for spotting it moljac024).

Offline

#4 2008-04-27 13:04:58

Kane
Member
Registered: 2006-10-08
Posts: 220

Re: [Solved] File permissions and ownerships

could it be that you need to change the ownership so the group is root too?

chown root:root test

Offline

#5 2008-04-27 13:36:35

faw
Member
Registered: 2007-06-09
Posts: 19

Re: [Solved] File permissions and ownerships

Hi Kane,

I would need users as the group so that my normal user could read the files, but yes, I tried that as well before I posted to see what happens - it still happens. I have even tried creating files and assigning ownership to my girlfriend's username so it seems to be happening regardless of username. (I set up an account for her but she never uses my machine so giving ownership to her username could be another way of me not deleting all of my albums by mistake, provided I can work this problem out).

Offline

#6 2008-04-27 13:51:36

dschrute
Member
From: NJ, USA
Registered: 2007-04-09
Posts: 183

Re: [Solved] File permissions and ownerships

Permission to delete ( and create ) files is set at the directory level.  So you need to confirm the permissions on the directory where "test" lives.
For example, if you have a directory with "drwxrwxr-x" for group" users" perms and owner, members of "users" can create and delete any files they have read access to in that directory.
Changing the perms to "drwxr-xr-x" for group "users" will still allow them to read, but not create/delete.

Last edited by dschrute (2008-04-27 13:52:53)

Offline

#7 2008-04-27 14:19:31

faw
Member
Registered: 2007-06-09
Posts: 19

Re: [Solved] File permissions and ownerships

I just created a test folder with those permissions, and bingo, as you mentioned. I knew that the directory permissions would control creating new files, but never realised it had that affect on deleting files. That's one to pencil into my notebook for sure.

Thank you dschrute!
Cheers,

Offline

Board footer

Powered by FluxBB