![如何限制用户只能执行/bin中的命令?](https://linux22.com/image/183231/%E5%A6%82%E4%BD%95%E9%99%90%E5%88%B6%E7%94%A8%E6%88%B7%E5%8F%AA%E8%83%BD%E6%89%A7%E8%A1%8C%2Fbin%E4%B8%AD%E7%9A%84%E5%91%BD%E4%BB%A4%EF%BC%9F.png)
我收到了一份包含几个问题的作业。其中一个问题是:
如何限制用户只能执行目录下的命令
/bin
?
我尝试使用以下命令来解决它,但它们不起作用。
# useradd -s /bin/bash localuser
# usermod -s /bin/rbash localuser
# mkdir /home/localuser/programs
以下是 的内容/home/localuser/.bash_profile
:
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$HOME/programs
export PATH
然后我尝试:
[localuser@example ~]$ ls
-rbash: ls: command not found
[localuser@example ~]$ less file1
-rbash: less: command not found
[localuser@example ~]$ clear
-rbash: clear: command not found
[localuser@example ~]$ date
-rbash: date: command not found
[localuser@example ~]$ ping redhat.com
-rbash: ping: command not found
# ln -s /bin/date /home/localuser/programs/
# ln -s /bin/ls /home/localuser/programs/
# ll /home/localuser/programs/
total 8
lrwxrwxrwx 1 root root 9 Oct 17 15:53 date -> /bin/date
lrwxrwxrwx 1 root root 7 Oct 17 15:43 ls -> /bin/ls
[localuser@example ~]$ date
Mon Oct 17 15:55:45 IST 2011
[localuser@example ~]$ ls
file1 file10 file2 file3 file4 file5 file6 file7 file8 file9 programs
[localuser@example ~]$ clear
-rbash: clear: command not found
# chattr +i /home/localuser/.bash_profile
你的答案是什么?