Allan Posted February 9, 2012 Share Posted February 9, 2012 what command would you use to make sure that you cannot easily delete a file called backup (which you own) without affecting other permissions? This is a question in a lab I'm doing. I've racked my brain, I've racked Google's brain. I've tried a TON of other things, and I can't seem to figure it out... can anyone help? Link to comment https://www.neowin.net/forum/topic/1056948-help/ Share on other sites More sharing options...
xendrome Posted February 9, 2012 Share Posted February 9, 2012 The question doesn't really make any sense.... "command"? Do they mean attribute? is this talking about security permissions? Link to comment https://www.neowin.net/forum/topic/1056948-help/#findComment-594641718 Share on other sites More sharing options...
Allan Posted February 9, 2012 Author Share Posted February 9, 2012 I'm assuming the professor is asking what chmod stuff I'd do. It's very badly written, though. Link to comment https://www.neowin.net/forum/topic/1056948-help/#findComment-594641724 Share on other sites More sharing options...
zoheb Posted February 9, 2012 Share Posted February 9, 2012 have a look at chattr command e.g : chattr +i filename. with this command the permissions does not change and nor you can edit or delete the file unless >>>> chattr -i filename Link to comment https://www.neowin.net/forum/topic/1056948-help/#findComment-594642398 Share on other sites More sharing options...
-Alex- Posted February 9, 2012 Share Posted February 9, 2012 have a look at chattr command e.g : chattr +i filename. with this command the permissions does not change and nor you can edit or delete the file unless >>>> chattr -i filename Good command, but chattr +u backup is probably better (makes the file only undeleteable). http://linux.about.com/od/commands/l/blcmdl1_chattr.htm Link to comment https://www.neowin.net/forum/topic/1056948-help/#findComment-594643080 Share on other sites More sharing options...
Allan Posted February 9, 2012 Author Share Posted February 9, 2012 Neither command worked. Link to comment https://www.neowin.net/forum/topic/1056948-help/#findComment-594643090 Share on other sites More sharing options...
-Alex- Posted February 9, 2012 Share Posted February 9, 2012 Upon closer inspection of the man page for chattr, +u would appear to be wrong: When a file with the `u' attribute set is deleted, its contents are saved. This allows the user to ask for its undeletion. But +i should work: A file with the `i' attribute cannot be modified: it cannot be deleted or renamed, no link can be created to this file and no data can be written to the file. Only the superuser or a process pessessing the CAP_LINUX_IMMUTABLE capability can set or clear this attribute. Link to comment https://www.neowin.net/forum/topic/1056948-help/#findComment-594643230 Share on other sites More sharing options...
ichi Posted February 9, 2012 Share Posted February 9, 2012 rm /bin/rm :D But then again if you don't want to screw the system, chattr +i is the way to go. AFAIK you must execute it as root, though, and root still can delete the file. It just prevents plain users from modifying it in any way. You could also make the file undeletable for every user including root using SELinux, or replace rm with the safe-rm wrapper and add your backup file to the blacklist. Link to comment https://www.neowin.net/forum/topic/1056948-help/#findComment-594643438 Share on other sites More sharing options...
zoheb Posted February 10, 2012 Share Posted February 10, 2012 With chattr +i , not even root cannot delete it. You need to use -i attribute Link to comment https://www.neowin.net/forum/topic/1056948-help/#findComment-594644442 Share on other sites More sharing options...
-Alex- Posted February 10, 2012 Share Posted February 10, 2012 With chattr +i , not even root cannot delete it. You need to use -i attribute You had it right first time, it's +i The operator `+' causes the selected attributes to be added to the existing attributes of the files; `-' causes them to be removed Link to comment https://www.neowin.net/forum/topic/1056948-help/#findComment-594644470 Share on other sites More sharing options...
Allan Posted February 10, 2012 Author Share Posted February 10, 2012 Correct answer is Chmod u-w backup Link to comment https://www.neowin.net/forum/topic/1056948-help/#findComment-594645858 Share on other sites More sharing options...
cybertimber2008 Posted February 10, 2012 Share Posted February 10, 2012 (edited) Correct answer is Chmod u-w backup That removes write permissions, but that doesn't prevent you from deleting the file, even in a regular, non-root account. [nick@fedora16vm ~]$ touch file.txt[nick@fedora16vm ~]$ ll file.txt-rw-rw-r-- 1 nick nick 0 Feb 10 13:06 file.txt[nick@fedora16vm ~]$ chmod u-w file.txt[nick@fedora16vm ~]$ ll file.txt-r--rw-r-- 1 nick nick 0 Feb 10 13:06 file.txt[nick@fedora16vm ~]$ rm file.txtrm: remove write-protected regular empty file `file.txt'? y[nick@fedora16vm ~]$ ll file.txtls: cannot access file.txt: No such file or directory[/CODE] Edit: /threadhijack: I'm unfamilar with the chattr, but highly interested... but I can't get it work. Any ideas? (Fedora 16) [CODE][nick@fedora16vm ~]$ chattr +i file.txtchattr: Operation not permitted while setting flags[/CODE] Link to comment https://www.neowin.net/forum/topic/1056948-help/#findComment-594646092 Share on other sites More sharing options...
Allan Posted February 10, 2012 Author Share Posted February 10, 2012 That was the answer the Professor gave me, and the program he wrote to check answers said it was correct... thus I have to accept it's wrong, even if it isn't. :s Link to comment https://www.neowin.net/forum/topic/1056948-help/#findComment-594646242 Share on other sites More sharing options...
-Alex- Posted February 10, 2012 Share Posted February 10, 2012 Print out this thread and give it to him :p Link to comment https://www.neowin.net/forum/topic/1056948-help/#findComment-594646446 Share on other sites More sharing options...
Recommended Posts