centos限制用户使用部分命令
参考网: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 chroot
ed 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限制用户使用部分命令的更多相关文章
- centos的用户管理相关命令所在的包
用户管理命令是指:useradd userdel groupadd groupdel 这些 这些命令出自一个叫 shadow-utils 的包. 对于配置文件 /etc/shadow ,则来自一个叫 ...
- Linux实战案例(4)CentOS清除用户登录记录和命令历史方法
CentOS清除用户登录记录和命令历史方法 清除登陆系统成功的记录[root@localhost root]# echo > /var/log/wtmp //此文件默认打开时乱码,可查到ip等信 ...
- CentOS 7 用户怎样安装 LNMP(Nginx+PHP+MySQL)
关于 Nginx (发音 “engine x”)这是一款免费.开源.高效的 HTTP 服务器,Nginx是以稳定著称,丰富的功能,结构简单,低资源消耗.本教程演示如何在CentOS 6.5服务器(适用 ...
- CentOS 7 用户账户配置
说明: 1.这篇博文记录的是CentOS 7 用户账户的配置,包括添加用户.添加用户组.删除用户.删除用户组等.其中包括分析用户的配置文件.目录以及对安全的思考. 2.用户配置方面CentOS 7与以 ...
- centos单用户模式:修改ROOT密码和grub加密
centos单用户模式:修改ROOT密码和grub加密 CentOSLinux网络应用配置管理应用服务器 Linux 系统处于正常状态时,服务器主机开机(或重新启动)后,能够由系统引导器程序自动引导 ...
- CentOS修改用户密码方法
CentOS修改用户密码方法 CentOS修改用户密码方法 1. 普通用户 a. 获取超级用户root权限 命令:su或者su -或者su - root b. passwd 用户名 2. 超级用户 a ...
- Centos硬盘IO性能检测命令iostat[转]
Centos硬盘IO性能检测命令iostat[转] 在Linux下频繁存取文件后,物理内存会很快被用光,当程序结束后,内存不会被正常释放,而是一直作为caching.这个问题,貌似有不少人在问,不过都 ...
- centos的用户、组权限、添加删除用户等操作的详细操作命令
1.Linux操作系统是多用户多任务操作系统,包括用户账户和组账户两种 细分用户账户(普通用户账户,超级用户账户)除了用户账户以为还 有组账户所谓组账户就是用户账户的集合,centos组中有两种类型, ...
- CentOS 修改用户密码
CentOS 修改用户密码 1.普通用户 ①获取超级用户root权限 命令:su 或者 su- 或者 su -root ②输入命令: passwd 用户名 ③输入新密码 2.超级用户 ①打开syste ...
随机推荐
- Django与Vue交互,实现注册的图片验证码没有加载的原因
注册功能之图片验证码: 1.实现过程: 传递uuid给后端,再发送图片验证码的请求给后端,后端存储uuid并生成图片验证码保存到redis,然后将图片验证码返回给前端. 当用户输入图片验证码的时候,前 ...
- centos 7 服务管理
启动一个服务:systemctl start firewalld.service关闭一个服务:systemctl stop firewalld.service重启一个服务:systemctl rest ...
- Qt QDateTime QTimer的简单实用
转载:N3verL4nd qttimer.h #ifndef QTTIMER_H #define QTTIMER_H #include <QDialog> namespace Ui { c ...
- ASP.NET重写Render 加载CSS样式文件和JS文件(切换CSS换皮肤)
网页换皮肤的方式有很多种,最简单的通常就是切换页面CSS,而CSS通常写在外部CSS文件里.那么切换CSS其实就是更换html里的link href路径.我在网上搜索了下. 一般有两种方式: 1.页面 ...
- 学习笔记之Data Visualization
Data visualization - Wikipedia https://en.wikipedia.org/wiki/Data_visualization Data visualization o ...
- 描述wxWidgets中事件处理的类型转化
wxWidgets是一个比较常用的UI界面库,我曾经试着使用wxWidgets写一个UI编辑工具,在此期间,学习了一些wxWidgets的知识.我对wxWidgets的绑定(Bind)比较好奇,想知道 ...
- keystone认证服务
实验操作平台:OpenStack单节点操作 一.相关概念 1.认证(authentication) 认证是确认允许一个用户访问的进程 2.证书(credentials) 用于确认用户身份的数据 3.令 ...
- 模拟远程SSH执行命令的编解码说明
模拟一个SSH“远程”执行命令并获取命令结果的一个程序: 1.在C/S架构下,当客户端与服务器建立连接(这里以TCP为例)后,二者可以不断的进行数据交互.SSH远程可以实现的效果是客户端输入命令可以在 ...
- 谷歌获取chromium
转自:http://blog.sina.com.cn/s/blog_496be0db0102voit.html 先参看 http://www.chromium.org/developers/how-t ...
- 删除win7任务栏通知区域图标的方法
大家都知道程序运行后会在任务栏的通知区域显示表明正在运行,但是有很多失效的图标也会在此显示,那么怎么样删除那些没用的图标呢? 1.在开始运行里输入:regedit进入注册表编辑器 2.进入注册表编辑器 ...