How to use rbash in linux

Rbash in Linux

One of the most powerful and fascinating Linux/GNU powered tool is the Linux Shell. Using the Linux shell, the whole Linux system is controlled.
It is used to restrict the features of bash shell in Linux. It provides restrictions for both the commands and the scripts running in the shell. It acts as an additional security force for the shell.

Restrictions Implemented using rbash

  • Altering the variables of the SHELL, PATH, ENV, or BASH_ENV.
  • Changing directories command will be disabled.
  • Switching output using the operators such as, ‘ > ’ , ‘ > |’ , ‘ < > ’ , ‘ > & ’ , ‘ & > ’ , and ‘ > > ’ .
  • Replace the shell command with another.
  • Enabling builtin commands with the -f and -d options.
  • Enable/disable shell with the help of enable builtin command
  • Specifying the -p option to the builtin command or a filename containing a slash as an argument to the -p option to the hash builtin command.
  • Turn off restricted mode with ‘ set +r’ / ‘ set +o restricted’ .
  • Specifying command names containing slashes.

To Enable Restricted Shell

In several favors of Linux/GNU like CentOS/Red Hat, it cannot be implemented directly. To achieve this we have to create symbolic links as follows.

[root@linuxhelp ~]# cd /bin
[root@linuxhelp bin]# ln -s bash rbash

To Start rbash

Run the following command to start rbash (restricted shell) in Linux.

[root@linuxhelp bin]# bash -r


OR

[root@linuxhelp bin]# rbash


To Test a Few Restrictions

Lets verify the restrictions using the following command.

[root@linuxhelp bin]# cd
rbash: cd: restricted


[root@linuxhelp bin]# cat >  file.txt
bash: file.txt: restricted: cannot redirect output

Advantages

  • Restricted shell is used along with a chroot jail, which provides a chance to limit access to the whole system.


Disadvantages

  • Use chroot with rbash only if you are clear with the process.
  • When we use bash it allows the unrestricted shells.
  • When a command that is found to be a shell script is executed, it turns off any restrictions in the shell spawned to execute the script.
  • Cannot be used for the entire untrusted software.
  • It is easily breakable.
Tag : Rbash
FAQ
Q
What are all the disadvantages of rbash in linux?
A
*Use chroot with rbash only if you are clear with the process.
*When we use bash it allows the unrestricted shells.
*When a command that is found to be a shell script is executed, it turns off any restrictions in the shell spawned to execute the script.
*Cannot be used for the entire untrusted software.
*It is easily breakable.
Q
how To Test a Few Restrictions in rbash?
A
type any command on "bin" it will display the error message "rbash: cd: restricted"
Q
What are the main advantages of rbash in Linux?
A
The restricted shell is used along with a chroot jail, which provides a chance to limit access to the whole system.
Q
How to Start rbash in Linux?
A
use following command to start rbash
bash -r
or
rbash
Q
how to enable the Restricted Shell in Linux?
A
use the following command
# ln -s bash rbash