I think prevent home folder from deleting is a very good idea. So I search possible approaches to do that. I that's what I’m find:
- Use
chattr +i /home/user
- even root can't can add/delete/rename user folder and all direct children in user - good and bad. Change owner of user directory to root and set sticky bit. Add file .keep and change his owner to root too:
chown root:user /home/user chmod 1775 /home/user chown root /home/user/.keep
root can delete /home/user, user can't. But user can freely add/remove/rename files in his directory
- Use
chattr +a /home/user
- same as first approach but user can add files.
I think chattr +a
on home directory: chattr +a /home
is the best way:
- We can create new home folders for other users without pain.
- We can freely edit files in /home/user
- We can't accidentally
sudo rm -rf /home/user
Actually the question: what are the pitfalls of this approach?
.keep
is enough, IMHO. – muru Dec 9 '14 at 7:55/home/user
, he'll be able to delete.keep
, even if it is owned by root under a sticky bit. – John WH Smith Dec 9 '14 at 8:14