Home Page Home Page
 Home | Software Development | System/Network Administration | Corporate Services | Resources | About Us
Monthly Server Management One-time Server Services Other Services
Network Administration Network Monitoring Network Security High Availability Load Balancing Data Backup and Recovery
Linux HOWTOs Linux Guides New RFCs Vulnerability list
Partners Careers Site Map
Restricted Shells

Chapter 21. Restricted Shells

Disabled commands in restricted shells

Running a script or portion of a script in restricted mode disables certain commands that would otherwise be available. This is a security measure intended to limit the privileges of the script user and to minimize possible damage from running the script.

Using cd to change the working directory.

Changing the values of the $PATH, $SHELL, $BASH_ENV, or $ENV environmental variables.

Reading or changing the $SHELLOPTS, shell environmental options.

Output redirection.

Invoking commands containing one or more /'s.

Invoking exec to substitute a different process for the shell.

Various other commands that would enable monkeying with or attempting to subvert the script for an unintended purpose.

Getting out of restricted mode within the script.

Example 21-1. Running a script in restricted mode


#  Starting the script with "#!/bin/bash -r"
#+ runs entire script in restricted mode.


echo "Changing directory."
cd /usr/local
echo "Now in `pwd`"
echo "Coming back home."
echo "Now in `pwd`"

# Everything up to here in normal, unrestricted mode.

set -r
# set --restricted    has same effect.
echo "==> Now in restricted mode. <=="


echo "Attempting directory change in restricted mode."
cd ..
echo "Still in `pwd`"


echo "\$SHELL = $SHELL"
echo "Attempting to change shell in restricted mode."
echo "\$SHELL= $SHELL"


echo "Attempting to redirect output in restricted mode."
ls -l /usr/bin > bin.files
ls -l bin.files    # Try to list attempted file creation effort.


exit 0