参考网:https://access.redhat.com/solutions/65822#

环境

  • Red Hat Enterprise Linux 5
  • Red Hat Enterprise Linux 6

问题

  • Need to restrict the normal users to run only limited set of commands assigned to him/her and all other commands for which normal user have permission to execute by-default, shall not be executed.

E.g: user XYZ can run only gzip and gunzip commands.

决议

Disclaimer : This is just a hack, not recommended for Actual Production Use

  • The normal user has been given permission to execute some commands which are available in /bin/ and /usr/local/bin/, So to remove those permissions and to restrict the user to run only particular set of commands, following steps shall be useful.

1. Create the restricted shell.

# cp /bin/bash /bin/rbash

2. Modify the target user for the shell as restricted shell

While creating user:

# useradd -s /bin/rbash localuser

For existing user:

# usermod -s /bin/rbash localuser

For more detailed information on this, please check the KBase Article 8349

Then the user localuser is chrooted and can't access the links outside his home directory /home/localuser

3. Create a directory under /home/localuser/, e.g. programs

# mkdir /home/localuser/programs

4. Now if you check, the user localuser can access all commands which he/she has allowed to execute. These commands are taken from the environmental PATH variable which is set in /home/localuser/.bash_profile. Modify it as follows.

# cat /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

Here the PATH variable is set to ~/programs directory, as /usr/local/bin is binded to /home/username/bin and /bin is binded to /home/username/bin so replacing that.

5. Now after logging with the username localuser, user cant run a simple command too. The output will be like this,

[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

6. Now create the softlinks of commands which are required for user localuser to execute in the directory /home/localuser/programs

# 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

Here examples of date and ls commands has been taken

7. Again login with user localuser and try to execute the commands.

[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

8. One more step can be added to restrict the user for making any modifications in their .bash_profile , as users can change it.

Run the following command to make the user localuser's .bash_profile file as immutable so that root/localuser can't modify it until root removes immutable permission from it.

# chattr +i /home/localuser/.bash_profile

To remove immutable tag,

# chattr -i /home/localuser/.bash_profile

Make file .bash_profile as immutable so that user localuser can't change the environmental paths.

centos限制用户使用部分命令的更多相关文章

  1. centos的用户管理相关命令所在的包

    用户管理命令是指:useradd userdel  groupadd groupdel 这些 这些命令出自一个叫 shadow-utils 的包. 对于配置文件 /etc/shadow ,则来自一个叫 ...

  2. Linux实战案例(4)CentOS清除用户登录记录和命令历史方法

    CentOS清除用户登录记录和命令历史方法 清除登陆系统成功的记录[root@localhost root]# echo > /var/log/wtmp //此文件默认打开时乱码,可查到ip等信 ...

  3. CentOS 7 用户怎样安装 LNMP(Nginx+PHP+MySQL)

    关于 Nginx (发音 “engine x”)这是一款免费.开源.高效的 HTTP 服务器,Nginx是以稳定著称,丰富的功能,结构简单,低资源消耗.本教程演示如何在CentOS 6.5服务器(适用 ...

  4. CentOS 7 用户账户配置

    说明: 1.这篇博文记录的是CentOS 7 用户账户的配置,包括添加用户.添加用户组.删除用户.删除用户组等.其中包括分析用户的配置文件.目录以及对安全的思考. 2.用户配置方面CentOS 7与以 ...

  5. centos单用户模式:修改ROOT密码和grub加密

    centos单用户模式:修改ROOT密码和grub加密 CentOSLinux网络应用配置管理应用服务器  Linux 系统处于正常状态时,服务器主机开机(或重新启动)后,能够由系统引导器程序自动引导 ...

  6. CentOS修改用户密码方法

    CentOS修改用户密码方法 CentOS修改用户密码方法 1. 普通用户 a. 获取超级用户root权限 命令:su或者su -或者su - root b. passwd 用户名 2. 超级用户 a ...

  7. Centos硬盘IO性能检测命令iostat[转]

    Centos硬盘IO性能检测命令iostat[转] 在Linux下频繁存取文件后,物理内存会很快被用光,当程序结束后,内存不会被正常释放,而是一直作为caching.这个问题,貌似有不少人在问,不过都 ...

  8. centos的用户、组权限、添加删除用户等操作的详细操作命令

    1.Linux操作系统是多用户多任务操作系统,包括用户账户和组账户两种 细分用户账户(普通用户账户,超级用户账户)除了用户账户以为还 有组账户所谓组账户就是用户账户的集合,centos组中有两种类型, ...

  9. CentOS 修改用户密码

    CentOS 修改用户密码 1.普通用户 ①获取超级用户root权限 命令:su 或者 su- 或者 su -root ②输入命令: passwd 用户名 ③输入新密码 2.超级用户 ①打开syste ...

随机推荐

  1. 【springboot】之利用shell脚本优雅启动,关闭springboot服务

    springbot开发api接口服务,生产环境中一般都是运行独立的jar,在部署过程中涉及到服务的优雅启动,关闭, springboot官方文档给出的有两种方式, 1.使用http shutdown ...

  2. sql server 2008 R2 备份还原到sql 2012

    从sql server 2008 r2备份的在sql server 2012中还原时一直读不到备份文件,然后把2008r2备份文件放到sql 2012的安装路径对应的Backup文件夹后可以读到了,不 ...

  3. Java NIO系列教程(三) Channel之Socket通道

    目录: <Java NIO系列教程(二) Channel> <Java NIO系列教程(三) Channel之Socket通道> 在<Java NIO系列教程(二) Ch ...

  4. centos 7扩展磁盘分区容量

    一.fdisk -l 查看磁盘空间大小 二. 1.fdisk /dev/sda 增加分区 2.判断应增加的分区号 键入n,增加一个分区 3.键入p,主分区,并键入(编号) 4.起始扇区和结束扇区(默认 ...

  5. [UE4]隐藏对象Set Visibility

    Propagate to Children:是否遍历子对象(用来设置子对象可见性)

  6. laravel插入数据时报 502 Bad Gateway

    前提:model中$timestamp = true; 但数据表中created_at 和updated_at  是默认为当前时间  造成冲突. 原因:用create方法时 created_at 和u ...

  7. 0000 - Spring 中常用注解原理剖析

    1.概述 Spring 框架核心组件之一是 IOC,IOC 则管理 Bean 的创建和 Bean 之间的依赖注入,对于 Bean 的创建可以通过在 XML 里面使用 <bean/> 标签来 ...

  8. CRM 2016 一个IFrame_A 刷新另一个 IFrame_B

    思路是 : 1 创建一个字段“new_xxx”. 2 注册字段 OnChange 事件. 3 OnChange 事件 刷新 IFrame_B子页面. CRM父页面JS: /// <summary ...

  9. Javascript-关于for in和forEach

    JS-for in:用来遍历对象 //遍历对象 for in var opts={name:'xiaofei',age:'28岁',job:'web前端工程师'} for (var k in opts ...

  10. (转)先装VS后装IIS产生问题的解决办法

    原文地址:http://www.cnblogs.com/mytechblog/articles/1897682.html 基于.net的web程序设计asp.net,我们就必须安装VS和IIS,但这二 ...