3

Let's assume that I have a webhosting server running on my ubuntu 13.04 system. For each customer I get that wants to host a website on my server I create a user and add it to a group called 'customers'. All of these customers get a private folder in my /home/ folder, in which there is a folder tree that should not be deleted. So let's say that one of my customers' name is bob. He will get /home/bob/ as his private folder, but that folder should also contain a folder tree like this:

/home/bob/
     |
     |-> /www/
         |
         |-> /bobsdomain.com/
         |              |
         |              |-> /public_html/
         |              |-> /cgi_bin/
         |
         |-> /bobsotherdomain.com/
                        |
                        |-> /public_html/
                        |-> /cgi_bin/

Bob should obviously be the owner of /home/bob because otherwise bob couldn't create or delete files and folders inside his home folder. However, everything between /www/ and /public_html/ or /cgi_bin/ should never be removed. Everything from /public_html/ or /cgi_bin/ and down should be bob's choice wether he wants to delete it or not.

In order to do this, could I just set the folders between /www/ and /public_html/ or /cgi_bin/ as property of root, or would that cause bob being unable to add files to the /public_html/ and /cgi_bin/ folders?
If this is not possible, in what other way should I do this?

3

I found the answer to my question. I chowned the folders that I didn't want to be deleted to root:root, and then chmodded these folders using 'the sticky bit' (1775 instead of 0775). This way everybody can add files and folders over ftp as they please, but they could not remove the folders that I protected with the sticky bit since you'd have to be a file or folder owner to do that.

2
  • You definitely do not want to do it this way. As you say, everybody can add files. If Mal knows that Bob is a user on your system, and can figure out Bob's username and the domain name (neither of which is difficult), then Mal can arbitrarily add files to Bob's website. Mal still wouldn't be able to delete files, but with cgi-bin access and the suexec features which are now common, Mal could arbitrarily delete and edit files that way. – wyrm May 18 '16 at 17:00
  • @gabi-barrientos: You may want to look at this answer and in particular chattr – Frank Nocke Nov 16 '16 at 11:33
0

You were on the right track. If you want to prevent actions like file creation and deletion (including deleting directories) then the user cannot have write access to the parent folder. In this case, to preserve /home/<user>/www/<domain>/public_html and /home/<user>/www/<domain>/cgi_bin, the user cannot have write access to /home/<user>/www/<domain>. To do that, the domain directories should be owned by somebody else and not world-writable. Note that it doesn't need to be root, either: the nobody user should be fine.

/home/bob
`-- [drwxrwxr-x bob     ]  www
    |-- [drwxrwxr-x nobody  ]  bobsdomain.com
    |   |-- [drwxrwxr-x bob     ]  cgi_bin
    |   `-- [drwxrwxr-x bob     ]  public_html
    `-- [drwxrwxr-x nobody  ]  bobsotherdomain.com
        |-- [drwxrwxr-x bob     ]  cgi_bin
        `-- [drwxrwxr-x bob     ]  public_html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.