The restricted mode of the Bourne shell sh, and its POSIX workalikes, is used when the interpreter is invoked in one of the following ways:
The restricted mode of Bash is used when Bash is invoked in one of the following ways:
Similarly KornShell's restricted mode is produced by invoking it thus:
For some systems (e.g., CentOS), the invocation through rbash is not enabled by default, and the user obtains a command not found error if invoked directly, or a login failure if the /etc/passwd file indicates /bin/rbash as the user's shell.
It suffices to create a link named rbash pointing directly to bash. Though this invokes Bash directly, without the -r or --restricted options, Bash does recognize that it was invoked through rbash and it does come up as a restricted shell.
This can be accomplished with the following simple commands (executed as root, either logged in as user root, or using sudo):
The following operations are not permitted in a restricted shell:
Bash adds further restrictions, including:4
Restrictions in the restricted KornShell are much the same as those in the restricted Bourne shell.5
The restricted shell is not secure. A user can break out of the restricted environment by running a program that features a shell function. The following is an example of the shell function in vi being used to escape from the restricted shell:
Or by simply starting a new unrestricted shell, if it is in the PATH, as demonstrated here:
Beyond the restricted modes of usual shells, specialized restricted shell programs include:
"POSIX sh specification". Archived from the original on 2014-12-21. Retrieved 2010-10-04. https://web.archive.org/web/20141221210713/http://pwet.fr/man/linux/commandes/posix/sh ↩
GNU Bash manual https://www.gnu.org/software/bash/manual/bashref.html#The-Restricted-Shell ↩
ksh manual, Solaris (SunOS 5.10) manual page, Oracle Inc. http://docs.sun.com/app/docs/doc/816-5165/ksh-1?l=en&n=1&a=view ↩
ksh(1) manual page, IBM AIX documentation set http://publib.boulder.ibm.com/infocenter/aix/v6r1/index.jsp?topic=/com.ibm.aix.baseadmn/doc/baseadmndita/korn_shell_restricted.htm ↩
Costales, Bryan; Assmann, Claus; Jansen, George; Shapiro, Gregory Neil (2007). Sendmail. Oreilly Series (4 ed.). O'Reilly Media, Inc. p. 379. ISBN 9780596510299. Retrieved 2012-08-02. As an aid in preventing [...] attacks, V8.1 sendmail first offered the smrsh (sendmail restricted shell) program. 9780596510299 ↩