Q:

Giving users Shell access with heavy restrictions

I am developing an in-house file-sharing system like Google Drive/Dropbox with very restricted shell access to users' own folder. The users have to be able to use mv ssh ls cd commands to access and navigate their own folders, also some users would be able to run gcc to compile their own program (But they are not allowed to run the programs they compiled). The only problem is I don't want people roaming around in system files or modifying system settings/variables.
First I thought maybe using containers/BSD Jails might be the solution but given that this system might have over 300 users, It adds unnecessary complexity and overhead.
What solutions are there on the open wild Internet?
Thanks!

A:

First, let me say, whatever you do in this area is subject to users finding creative ways to get around what you've put in place.
Bash provides the concept of a "restricted shell" that will prevent users from using cd and limit them only to the commands that pre-exist in their path.  You could create a directory that contains symbolic links to the set of "allowed" commands, and configure the user's path to point to that directory:
https://www.gnu.org/software/bash/manual/html_node/The-Restricted-Shell.html
$ PATH=/tmp/ex rbash
$ ls
src
$ cd /
rbash: cd: restricted
$ export PATH=/usr/bin:$PATH
rbash: PATH: readonly variable
$

Note, however, that if you put a command in the path that can exec arbitrary commands, this won't help:
$ rbash
$ cd /tmp
rbash: cd: restricted
$ vim
:!/bin/bash
$ cd /tmp
$

Even the documentation for Bash's restricted shell says:

Modern systems provide more secure ways to implement a restricted environment, such as jails, zones, or containers.

