linux如和对其他用户隐藏进程?

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三个等级,由底到高防御增强。

  1. hidepid=0 - 经典模式 - 任何人都可以访问/proc//*文件夹下所有的可阅读文件 (默认).
  2. hidepid=1 - 敏感保护 - 文件夹/proc/下敏感的文件如:cmdline, sched*, status不被允许他人访问
  3. 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

保存退出。

视频参考:https://www.cyberciti.biz/media/new/faq/2014/08/hidepid-demo.gif

转载:

1、http://blog.csdn.net/ly890700/article/details/62428955

2、https://www.cyberciti.biz/faq/linux-hide-processes-from-other-users/

原文地址:https://www.cnblogs.com/shengulong/p/7892217.html