allenle@backupabc:~$ cat retrictedshell.sh
#!/bin/bash
echo
echo "I am in `pwd`"
echo "Changing directory."
cd /usr
echo "New dirctory in `pwd`"
echo "Coming back home."
cd -
echo "I am again in `pwd`"
echo "--------------------restricted shells------------------------------"
set -r
#or set --restricted
echo "==> Now in restricted mode. <=="
echo
echo
echo "Tring directory change in restricted mode."
cd ..
echo "I am in `pwd`"
echo
echo
echo "\$SHELL = $SHELL"
echo "Attempting to change shell in restricted mode."
SHELL="/bin/ash"
echo
echo "\$SHELL= $SHELL"
echo
echo
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.
echo
exit 0

从结果图看,在非受限模式下,变更目录的操作成功了。
当改变了shell模式为受限模式(set -r),cd命令变更目录的操作就不成功了。
不仅如此,当试图修改$shell变量时,也是失败的。
注:脚本开头以"#!/bin/bash -r"来调用,则以受限模式运行脚本。








![[附源码]JAVA毕业设计抗击新冠疫情专题宣传网站(系统+LW)](https://img-blog.csdnimg.cn/8626ba7453da4f43829805da6393379f.png)








![[附源码]Python计算机毕业设计Django楼盘销售管理系统](https://img-blog.csdnimg.cn/4cb2eca455744795b9250235afd1b553.png)
