LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 10-18-2015, 10:09 PM   #1
lixiaohui
LQ Newbie
 
Registered: Oct 2015
Posts: 2

Rep: Reputation: Disabled
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?
 
Old 10-18-2015, 10:14 PM   #2
frieza
Senior Member
 
Registered: Feb 2002
Location: harvard, il
Distribution: Ubuntu 11.4,DD-WRT micro plus ssh,lfs-6.6,Fedora 15,Fedora 16
Posts: 3,233

Rep: Reputation: 406Reputation: 406Reputation: 406Reputation: 406Reputation: 406
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.
 
1 members found this post helpful.
Old 10-18-2015, 10:19 PM   #3
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,779

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
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.
 
Old 10-19-2015, 01:36 AM   #4
HMW
Member
 
Registered: Aug 2013
Location: Sweden
Distribution: Debian, Arch, Red Hat, CentOS
Posts: 773
Blog Entries: 3

Rep: Reputation: 369Reputation: 369Reputation: 369Reputation: 369
Quote:
Originally Posted by rknichols
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 View Post
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.
The chattr way was interesting!

Best regards,
HMW
 
Old 10-19-2015, 07:01 AM   #5
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,779

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
Quote:
Originally Posted by HMW View Post
^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.
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.
 
Old 10-19-2015, 08:03 AM   #6
HMW
Member
 
Registered: Aug 2013
Location: Sweden
Distribution: Debian, Arch, Red Hat, CentOS
Posts: 773
Blog Entries: 3

Rep: Reputation: 369Reputation: 369Reputation: 369Reputation: 369
Quote:
Originally Posted by rknichols View Post
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!
 
Old 10-19-2015, 10:27 AM   #7
lixiaohui
LQ Newbie
 
Registered: Oct 2015
Posts: 2

Original Poster
Rep: Reputation: Disabled
Thumbs up Thank you very much!!!

Quote:
Originally Posted by rknichols View Post
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!
 
Old 10-27-2015, 05:39 AM   #8
hortageno
Member
 
Registered: Aug 2015
Distribution: Ubuntu 22.04 LTS
Posts: 240

Rep: Reputation: 67
Quote:
Originally Posted by lixiaohui View Post
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.
 
  


Reply



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
[SOLVED] dovecot: cannot read/write to folder (file) boxb29 Linux - Server 1 08-15-2009 12:53 AM
share folder (read/write) Winanjaya Linux - Newbie 3 10-06-2008 07:24 AM
USB HardDrive mounts read-only. Is there anyway to make it read-write? Fritz_Katz Linux - Hardware 7 09-13-2007 06:50 PM
Can read but not write to FTP folder MrDooDooHead Linux - Newbie 3 02-13-2007 07:42 PM
how to share folder (read, write and execute) into the network redline1022 Linux - Networking 3 11-15-2006 01:13 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 12:41 PM.

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