Using chroot and restricted Bash shells to secure scripts
In this recipe, we will learn about chroot and restricted bash(rbash). The chroot
command is used to change the root directory. Using rbash, we can restrict some features of the bash shell for some security purposes.
Getting ready
Besides having a Terminal open, you need to ensure that rbash
is installed in the system.
How to do it…
- Now, we will look at the command to start
rbash
. Run the following command:
$ bash -r or $ rbash
- Now we will test some restrictions. First, we will try to change the directory. Run the following command:
$ cd work/
Next, we will try to write some contents to the file. Run the given command to write some contents into the file:
ls > log.txt
How it works…
After using rbash
, access to the system will be limited. In the preceding examples, we started the restricted shell by typing bash -r
or rbash
.
Next, we tried to change the directory, but we got the rbash: cd: restricted
message, so we cannot change the directory...