linux 实现普通用户只允许使用部分命令

linux 实现普通用户只允许使用部分命令

 

由于公司奇葩需求,需要给所有开发用户开通所有服务器的只能查看权限,结合现有jumpserver实现扩展,搭建jumpserver省略,推送一个普通用户


接下来的操作都是在系统里,这里我写了一个脚本用于实现,只允许check_user用户执行 cat ls tail tailf命令

#!/bin/bash

User="check_user"
Command="cat ls tail tailf"

ln -s /bin/bash /bin/rbash
User_alive=`cat /etc/passwd | grep check_user|wc -l`
if [ $User_alive -eq 1 ]
then
    sed -i "/$User/s/\/bin\/bash/\/bin\/rbash/" /etc/passwd
    mkdir /home/$User/bin
    touch /home/$User/.bash_profile
    if [ -f /home/$User/.bash_profile ]
    then
        chown root. /home/$User/.bash_profile
        chmod 755 /home/$User/.bash_profile
        echo > /home/$User/.bash_profile
cat >> /home/$User/.bash_profile <<EOF 
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

PATH=\$HOME/bin
EOF
    else
        echo "profile is not exist"
        exit "6"
    fi
else
    echo "User is not exist"
    exit 5
fi
for i in $Command
do
    dir=`whereis $i | awk "{print $2}"`
    ln -s $dir /home/$User/bin
done

 

以上转自

转自https://blog.51cto.com/chentianwang/2062053

 

 

 

实现后发现后续问题目前还没有解决
1,本想把cd加上,但是centos是可以,ubuntu是不可以,因为cd在ubuntu里不算命令是内置内核里的,不知怎么解决
2,tab补全功能有的机器可以,有的不可以不知道为什么

这边测试了直接cd 不行

centos7和centos6的cd位置也不一样

后面发现cd 需要先执行一下bash才可以,而且必须是root切换到read_user才可以。

https://en.wikipedia.org/wiki/Restricted_shell

在/usr/bin下查看cd 还是需要bash执行。

只能修改Command="bash cd cat ls tail tailf",这样用户会有执行bash的权限。还是要根据实际情况设置。

 

 

 

 

  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值