小計一下(Restricted shell)

假如我們需要限制一個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

到此配置結束,登陸測試:

wKiom1UL03Pyymq3AAHJuVyyfs8844.jpg


測試效果還是很明顯的。具體的限制的shell有哪些限制,wiki上有詳細的說明:


wKiom1UL1AKSpu0HAAFT1lgW_A0248.jpg



點擊連接地址.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章