The restricted shell is a
Unix shell
A Unix shell is a command-line interpreter or shell that provides a command line user interface for Unix-like operating systems. The shell is both an interactive command language and a scripting language, and is used by the operating system t ...
that restricts some of the capabilities available to an interactive user session, or to a
shell script
A shell script is a computer program designed to be run by a Unix shell, a command-line interpreter. The various dialects of shell scripts are considered to be scripting languages. Typical operations performed by shell scripts include file manip ...
, running within it. It is intended to provide an additional layer of security, but is insufficient to allow execution of entirely untrusted software. A restricted mode operation is found in the original
Bourne shell
The Bourne shell (sh) is a shell command-line interpreter for computer operating systems.
The Bourne shell was the default shell for Version 7 Unix. Unix-like systems continue to have /bin/sh—which will be the Bourne shell, or a symbolic link ...
[POSIX sh specification](_blank)
/ref> and its later counterpart ,
/ref> and in the KornShell
KornShell (ksh) is a Unix shell which was developed by David Korn at Bell Labs in the early 1980s and announced at USENIX on July 14, 1983. The initial development was based on Bourne shell source code. Other early contributors were Bell ...
.[ksh manual](_blank)
Solaris (SunOS 5.10) manual page, Oracle Inc. In some cases a restricted shell is used in conjunction with a chroot
A chroot on Unix and Unix-like operating systems is an operation that changes the apparent root directory for the current running process and its children. A program that is run in such a modified environment cannot name (and therefore normall ...
jail, in a further attempt to limit access to the system as a whole.
Invocation
The restricted mode of the Bourne shell , and its POSIX workalikes, is used when the interpreter is invoked in one of the following ways:
* ''note that this conflicts with the "read" option in some variants''
* ''note that this may conflict with the remote shell
The remote shell (rsh) is a command line computer program that can execute shell commands as another user, and on another computer across a computer network.
The remote system to which ''rsh'' connects runs the ''rsh'' daemon (rshd). The daemon ...
command, which is also called on some systems''
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:
*
*
Setting up rbash
For some systems (e.g., CentOS), the invocation through is not enabled by default, and the user obtains a error if invoked directly, or a login failure if the /etc/passwd
passwd is a command on Unix, Plan 9, Inferno, and most Unix-like operating systems used to change a user's password. The password entered by the user is run through a key derivation function to create a hashed version of the new password, whi ...
file indicates as the user's shell.
It suffices to create a link named pointing directly to . Though this invokes Bash directly, without the or options, Bash does recognize that it was invoked through 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
sudo ( or ) is a program for Unix-like computer operating systems that enables users to run programs with the security privileges of another user, by default the superuser. It originally stood for "superuser do", as that was all it did, and it ...
):
root@host:~# cd /bin
root@host:/bin# ln bash rbash
Limited operations
The following operations are not permitted in a restricted shell:
* changing directory
* specifying absolute pathnames or names containing a slash
* setting the PATH or SHELL variable
* redirection of output
Bash adds further restrictions, including:
* limitations on function definitions
* limitations on the use of slash-ed filenames in Bash builtins
Restrictions in the restricted KornShell are much the same as those in the restricted Bourne shell.[ksh(1) manual page](_blank)
IBM AIX documentation set
Weaknesses of a restricted shell
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:
user@host:~$ vi
:set shell=/bin/sh
:shell
Or by simply starting a new unrestricted shell, if it is in the , as demonstrated here:
user@host:~$ rbash
user@host:~$ cd /
rbash: cd: restricted
user@host:~$ bash
user@host:~$ cd /
user@host:/$
List of programs
Beyond the restricted modes of usual shells, specialized restricted shell programs include:
* rssh
/code> – used with OpenSSH
OpenSSH (also known as OpenBSD Secure Shell) is a suite of secure networking utilities based on the Secure Shell (SSH) protocol, which provides a secure channel over an unsecured network in a client–server architecture.
Network Working G ...
, permitting only certain file copying programs, namely scp
SCP may refer to:
Organizations Political parties
* Soviet Communist Party, the leading political party in the former Soviet Union
* Syrian Communist Party
* Sudanese Communist Party
* Scottish Christian Party
Companies
* Seattle Computer Produ ...
, sftp, rsync
rsync is a utility for efficiently transferring and synchronizing files between a computer and a storage drive and across networked computers by comparing the modification times and sizes of files. It is commonly found on Unix-like operatin ...
, cvs
CVS may refer to:
Organizations
* CVS Health, a US pharmacy chain
** CVS Pharmacy
** CVS Caremark, a prescription benefit management subsidiary
* Council for Voluntary Service, England
* Cable Video Store, former US pay-per-view service
* CVS F ...
, and rdist
* smrsh
, which limits the commands sendmail
Sendmail is a general purpose internetwork email routing facility that supports many kinds of mail-transfer and delivery methods, including the Simple Mail Transfer Protocol (SMTP) used for email transport over the Internet.
A descendant of the ...
can invoke[
]
See also
* Remote Shell
The remote shell (rsh) is a command line computer program that can execute shell commands as another user, and on another computer across a computer network.
The remote system to which ''rsh'' connects runs the ''rsh'' daemon (rshd). The daemon ...
References
{{reflist
Command shells