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


相关文章
|
1天前
|
安全 Linux 测试技术
|
1天前
|
安全 Linux Windows
Linux中Shutdown命令使用介绍
Linux中Shutdown命令使用介绍
|
2天前
|
缓存 关系型数据库 Linux
Linux目录结构:深入理解与命令创建指南
Linux目录结构:深入理解与命令创建指南
|
2天前
|
数据挖掘 Linux vr&ar
Linux命令实战:解决日常问题的利器
Linux命令实战:解决日常问题的利器
|
2天前
|
NoSQL Linux Redis
Redis的介绍,以及Redis的安装(本机windows版,虚拟机Linux版)和Redis常用命令的介绍
Redis的介绍,以及Redis的安装(本机windows版,虚拟机Linux版)和Redis常用命令的介绍
15 0
|
2天前
|
安全 Linux Shell
linux基础命令详解
linux基础命令详解
8 0
|
3天前
|
Linux
Linux常用命令2
Linux常用命令2
5 0
|
3天前
|
Linux
Linux常用命令1
Linux常用命令1
9 0
|
3天前
|
人工智能 Linux Shell
linux命令-条件判断-test
linux命令-条件判断-test
8 1