更新时间:2022-09-16 15:17:23
假如我们需要限制一个Linux用户只能使用我们指定的命令,那么可以使用限制的shell。
在正常的命令环境下使用:
1
2
3
4
5
|
测试: # bash -r # 进入限制的shell # cd / bash: cd: restricted # exit |
具体设置:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# 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上有详细的说明:
本文转自Mr_陈 51CTO博客,原文链接:http://blog.51cto.com/chenpipi/1622584,如需转载请自行联系原作者