linux阻止程序命令,Linux下防止用户查看他人的进程-hidepid

本人水平非常有限,权当笔记看

Linux kernel 3.2以上,root用户可以设置内核,让普通用户看不到其它用户的进程。适用于有多个用户使用的系统。该功能由内核提供,因此本教程适用于Debian/Ubuntu/RHEL/CentOS等。

原理

Linux中,可以通过/proc文件系统访问到许多内核的内部信息。/proc文件系统最初的设计也是用于方便地访问进程相关的信息,因此命名为proc。现在这个文件系统已用于反映系统中方方面面的信息,例如/proc/modules是模块的列表,/proc/meminfo则是内存使用的统计。/proc文件系统中的目录并非持久存储的信息,也就是说,其目录并不“真实”地存在于磁盘,而是在访问时动态生成。

我们感兴趣的是/proc文件系统中关于进程的信息。每一个进程在/proc文件系统中有一个目录即(/proc/),目录名即进程号。self目录是一个链接,指向当前进程。

ps命令和top命令从/proc文件系统中读取进程信息并显示出来。因此,如果一个进程的进程号没有在/proc文件系统中反映出来,则这个进程被“隐藏”了,“隐藏”进程在ps或top命令的输出不出现。

hidepid 选项解释

该选项定义了一个Linux用户可以查看到多少其它用户的信息。保护级别分0、1、2三个等级,由底到高防御增强。

hidepid=0 - 经典模式 - 任何人都可以访问/proc//*文件夹下所有的可阅读文件 (默认).

hidepid=1 - 敏感保护 - 文件夹/proc/下敏感的文件如:cmdline, sched*, status不被允许他人访问

hidepid=2 - 强力保护 - It means hidepid=1 plus all

/proc/PID/ will be invisible to other users. It compicates intruder's

task of gathering info about running processes, whether some daemon runs

with elevated privileges, whether another user runs some sensitive

program, whether other users run any program at all, etc.

内核保护:隐藏其它用户的进程

通过下面命令可令配置立即生效:

# mount -o remount,rw,hidepid=2 /proc

编辑/etc/fstab文件,使配置在服务器启动时自动生效

# vi /etc/fstab

proc /proc proc defaults,hidepid=2 0 0

保存退出。

举例:防止用户查看他人的进程

下面是一个例子

$ ssh vivek@cbz-test

$ ps -ef

$ sudo -s

# mount -o remount,rw,hidepid=2 /proc

$ ps -ef

$ top

$ htop

实战记录:

gif动画: hidepid 实战

Tip: Dealing with apps that breaks when you implement this technique

You need to use gid=VALUE_HERE option:

gid=XXX defines a group that will be able to gather all processes' info

(as in hidepid=0 mode). This group should be used instead of putting

nonroot user in sudoers file or something. However, untrusted users

(like daemons, etc.) which are not supposed to monitor the tasks in the

whole system should not be added to the group.

So add the user called see process information and mount /proc as follows in /etc/fstab:

proc /proc proc defaults,hidepid=2,gid=admin 0 0

原文: 译文: 转载请保留链接

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值