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

由于公司奇葩需求,需要给所有开发用户开通所有服务器的只能查看权限,结合现有jumpserver实现扩展,搭建jumpserver省略,推送一个普通用户linux实现普通用户只允许使用部分命令
接下来的操作都是在系统里,这里我写了一个脚本用于实现,只允许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

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


本文转自 转身撞墙角 51CTO博客,原文链接:http://blog.51cto.com/chentianwang/2062053


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值