How to make a folder can read write but can not remove itself?
Linux - SecurityThis forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
How to make a folder can read write but can not remove itself?
I need open a folders to each custom as his or her home folder. To let he or she make new files, new child folders, edit rename and remove his or her files and folders. But forbid he or she remove his or her home folder.
I know if those home folder made under root, just like /homefolder, I can use the commend "chmod 1777 /homefolder". but if custom's home folder made in a authorized folder, just like /home/user/server/customNameFolder, that commend does not work.
I have search on google and baidu just like this subject and some other same meaning words. But I have not got the answer. So I want to ask you if there is no way to get my goal?
Distribution: Ubuntu 11.4,DD-WRT micro plus ssh,lfs-6.6,Fedora 15,Fedora 16
Posts: 3,233
Rep:
a simple solution i found here http://binblog.info/2011/01/30/make-...able-on-linux/
the short of it is put a hidden file in their folder and make it immutable, since you can't remove an immutable file and you can't remove a non empty folder you can't accidentally delete the folder.
Removing a directory ("folder") requires write permission in the parent directory. If that parent directory is owned and writeable only by root, then the user would not be able to delete that custom home directory.
If that parent directory is owned and writeable only by root, then the user would not be able to delete that custom home directory.
^That would work, but the OP specified:
Quote:
Originally Posted by lixiaohui
I need open a folders to each custom as his or her home folder. To let he or she make new files, new child folders, edit rename and remove his or her files and folders. But forbid he or she remove his or her home folder.
Originally Posted by lixiaohui
I need open a folders to each custom as his or her home folder. To let he or she make new files, new child folders, edit rename and remove his or her files and folders. But forbid he or she remove his or her home folder.
I don't see any conflict there. The use can own the directory, but not its parent. That's the same as the relationship between /home/someuser and /home. The user has full permission within /home/someuser, but cannot remove that directory because /home is writeable only by root.
I don't see any conflict there. The use can own the directory, but not its parent. That's the same as the relationship between /home/someuser and /home. The user has full permission within /home/someuser, but cannot remove that directory because /home is writeable only by root.
Ah, yes, of course. My bad! I totally misread your post, my apologies!
Removing a directory ("folder") requires write permission in the parent directory. If that parent directory is owned and writeable only by root, then the user would not be able to delete that custom home directory.
I have try it. I have made a test folder in /home/user/. Change it's owner by the commend: sudo chown root:root test. Then I make a child folder in test: sudo mkdir /home/user/test/testhome. At the end I change the access permit: sudo chmod 1777 /home/user/test/testhome.
After that, I try to remove the testhome. It is forbidden. Make new file/folder, rename them, edit file, remove them, all the operate works great. Thank you. Thank you very much. Thanks for hmw and frieza too!
I have try it. I have made a test folder in /home/user/. Change it's owner by the commend: sudo chown root:root test. Then I make a child folder in test: sudo mkdir /home/user/test/testhome. At the end I change the access permit: sudo chmod 1777 /home/user/test/testhome.
After that, I try to remove the testhome. It is forbidden. Make new file/folder, rename them, edit file, remove them, all the operate works great. Thank you. Thank you very much. Thanks for hmw and frieza too!
Just be careful with the 777 permissions. It's not required in almost all cases.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.