Is it possible to prevent any user to not use commands like ls, rm and other system commands which could harm the system. But the users should be able to execute shell programs.
Is it possible to prevent any user to not use commands like ls, rm and other system commands which could harm the system. But the users should be able to execute shell programs.
Your question should be:
I don't trust my users. The dumb ones see something on the internet and try it out without understanding what it does. The devious ones like to snoop around and look at other peoples files and steal their ideas. And the lazy, don't get me started on the lazy ones.
How do I protect my system and my users from my users?
First, unix has very a very comprehensive filesystem permissions system. This seems to be a decent tutorial on unix filesystem permissions. The gist of this is that directories can be set such that a user can go into a directory and can run programs out of that directory but can't view the contents of that directory. If you do this, for example, on /home, if the user runs ls on /home, they get a permission denied error.
If you're really scared of your users and want to stick them in a supermax type of restricted environment, use something like freebsd's jails or solaris's zones -- each user gets their own tailor made environment. For added points use ZFS so you can take a snapshot of the environment when they log in so if they delete their files you can just pull them out of the snapshot.
There are three things that need to be in place to fully do what you're asking for:
Belt, suspenders, and a staple-gun for good measure. Hard to go wrong there.
AppArmor is interesting since the MAC for a specific executable is inherited by all of its children. Set a user's login to be
/bin/bash-bob
, set the AppArmor profile for that specific binary right, and the only way they're getting out of that permission jail is through kernel exploits. If some lazy install script left/var/opt/vendor/tmp
global-writeable for some stupid reason, the user using/bin/bash-bob
as their shell won't be able to write there. Set the bash-bob profile to only allow writing to their home directory and/tmp
, and such permission mistakes can't be leveraged. Even if they somehow find the root password, the AppArmor profile for/bin/bash-bob
will still apply even after theysu
up sincesu
and thebash
process it spawns are children of/bin/bash-bob
.The hard part is building that AppArmor profile.
In my opinion, you only need steps 2 and 3, since in combination they both prevent the ability to do anything harmful outside of the carefully constructed box you set up in both those steps.
Well, you can set the user's shell to a program you've written that only lets them run certain shell scripts.
Of course this would only be as secure as the program and shell scripts; in practice, this kind of restricted shell typically isn't secure against a smart attacker.
Don't try and limit commands, limit file permissions. You can't practically limit people's access to syscalls, so all someone needs to do is provide their own copy of whatever "dangerous" commands you don't want them to execute, and you're stuffed.
If you want the user to only be able to execute certain scripts/binaries, you can use a restricted shell. This (as the Wikipedia article mentions) isn't completely secure, but if you can guarantee that no application allowed to run is able to execute a new shell then it is a good alternative.
To setup a users restricted shell, set
/bin/rbash
(or similar, most shells enter restricted mode when the binary is named r***name*) as the users shell. Then, edit **.bashrc (or equivalent) and set$PATH
to a directory where all allowed binaries/scripts are stored.Yes, it's possible, but in practice it would take a lot of work and planning. You can create scripts and have them run as a privileged use, then remove all privileges from the user in question. Or, you can set the user's shell to something of your own making that lets them do only what you explicitly allow.
However, standard permissions in linux make it nearly impossible for a normal user to "harm the system". What sort of harm are you trying to prevent? It's trivial to prevent users from being able to install software or run programs outside of their home directory, and you can use chroot to lock down the system even further.
You may want to try [lshell][1] (limited shell).
[1]: http://lshell.ghantoos.org/Overview lshell
The way I usually implement this kind of restrictions requires that several conditions are met, otherwise the restriction can be easily circumvented:
wheel
group, the only one authorized to usesu
(enforced via PAM).The user is given a properly secured
rbash
with a read-onlyPATH
pointing to a private~/bin
, this~/bin/
directory contains links to simple utilities:the user is given a restricted, read-only environment (think of stuff like
LESSSECURE
,TMOUT
,HISTFILE
variables).staff_u
and given rights to execute commands as other user as required viasudo
.the user's
/home
,/tmp
and possibly/var/tmp
are polyinstantiated via/etc/security/namespace.conf
:Also,
/etc/security/namespace.init
makes all skeletal files readonly for the user and owned byroot
.This way you can choose whether
$USER
can execute any command on his/her own behalf (via a link in the private~/bin
directory, provisioned via/etc/skel
, as explained above), on behalf of other user (viasudo
) or none at all.Yes, just change the permissions on these commands.
You might have a better fighting chance by writing a shell command that behaves as to your requirements.
What's not appropriate of the default permissions for normal users on Linux?