假如我們需要限制一個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上有詳細的說明: