How to block command, let say mkdir for specific user ?
What I did just created read-only function and store in users profile ~/.bashrc
/bin/mkdir() {
echo "mkdir command not allow for you"
}
mkdir() {
echo "mkdir command not allow for you"
}
./mkdir() {
echo "mkdir command not allow for you"
}
readonly -f /bin/mkdir
readonly -f mkdir
readonly -f ./mkdir
Test:
rahul@ubuntu:~$ cd /bin/
rahul@ubuntu:/bin$ ./mkdir /home/rahul/ggg
mkdir command not allow for you
rahul@ubuntu:/bin$ cd
rahul@ubuntu:~$ mkdir testing
mkdir command not allow for you
rahul@ubuntu:~$ /bin/mkdir testing
mkdir command not allow for you
So my question is What should be the way of achieving this ? is there any tool for this ?
Update 1 # But if user is smart , he could copy mkdir binary and rename it and use it . So how to achieve this ?
mkdirand rename it, or even just copy and rename the existing binary. Also, there's a shell builtin for overriding aliases and functions.cp /bin/mkdir mkdir2then use it :(cp -r /usr/local/lib gggwill create a directory calledggg(containing a copy of the contents of/usr/local/lib, if any, which the user can then just delete). You can usefind / -type d -emptyto find an empty directory to copy.