假如我们需要限制一个Linux用户只能使用我们指定的命令,那么可以使用限制的shell。
在正常的命令环境下使用:
测试:
# bash -r # 进入限制的shell
# cd /
bash: cd: restricted
# exit
具体设置:
# useradd test # 添加用户
# cd bin
# ln -s bash rbash # 设置软连接
# cd /home/test
# vim .bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
#PATH=$PATH:$HOME/bin # 注释掉原来的PATH路径
PATH=$HOME/.bin
export PATH
# mkdir .bin
# ln -s /bin/ls .bin/
# ln -s /bin/cat .bin/
# ln -s /bin/touch .bin/ # 给用户指定命令
#
# vim /etc/passwd
test:x:502:502::/home/test:/bin/rbash # 修改shell为rbash
#
# passwd test
到此配置结束,登陆测试:
测试效果还是很明显的。具体的限制的shell有哪些限制,wiki上有详细的说明: