Ubuntu – Give access to only specific directory for a sudo user

14.04permissionssudo

How to create a sudo user such that when logged in to server will be redirected to a specific directory.

For example if I want to give access only to /var/www/html/my-site directory for that user. As soon as that user is logged in, can view content only under the my-site directory (even the path shown should be /my-site only), and should not be able to access other directories under html directory.

I referred this answer and followed all the steps but still that user can access all the folders. How to restrict it?

Best Answer

What you're asking for is essentially known as a jail, wherein a user is confined to a certain subset of the system (like say, the home folder). Fortunately, users on Linux already have a home folder setup, so you can just use this jail.

Now, setting up a jail is a complicated matter, and is out of the scope of this question.

Now, assuming you have a working jail, you can just bind the proper folder to the user home:

mount --bind /var/www/username /home/username/www

Although, this honestly is not a good option. If you're just hosting a user, allow them to connect over FTP and just jail them to their "home" (the folder they have admin to). There is no need for them to have a shell on your server.

The question you linked has a very good concept of how to jail users, but it only works with FTP and derivatives, not with raw SSH itself. And, as I mentioned before, running raw SSH is a really bad idea.

Finally, it seems as though you're acting as a web host. Why not just use a control panel like Froxlor? It takes care of most of the heavy lifting for you, and allows you to set quotas and other things that may be of interest. Plus it manages FTP jails and similar automatically for you, allowing you to bypass the headache that is jailing.