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
保存退出。
視頻參考: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/