假如我們需要限制一個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
到此配置結束,登陸測試:
![](https://img.laitimes.com/img/_0nNw4CM6IyYiwiM6ICdiwiInBnauQDN4gzcmlXeWVnSIFUQzEXb5lHUzADTVFTbvl2S39CXxkzLcJUNvwFMw00LcJDMzZWe39CXt92Yu8GdjFTNuMzcvw1LcpDc0RHaiojIsJye.jpg)
測試效果還是很明顯的。具體的限制的shell有哪些限制,wiki上有詳細的說明: