Linux: Hide Processes From Other Users

by on August 21, 2014 · 7 comments· LAST UPDATED August 21, 2014

in , ,

I run a multi-user system. Most users access resources using ssh client. How can I stop leaking process information to all users on Linux operating systems? How do I prevent users from seeing processes that do not belong to them on a Debian/Ubuntu/RHEL/CentOS Linux server?

If you are using Linux kernel version 3.2+ (or RHEL/CentOS v6.5+ above) you can hide process from other users. Only root can see all process and user only see their own process. All you have to do is remount the /proc filesystem with the Linux kernel hardening hidepid option.
Tutorial details
DifficultyEasy (rss)
Root privilegesYes
RequirementsLinux kernel v3.2+
Estimated completion time2m

Say hello to hidepid option

This option defines how much info about processes we want to be available for non-owners. The values are as follows:

  1. hidepid=0 - The old behavior - anybody may read all world-readable /proc/PID/* files (default).
  2. hidepid=1 - It means users may not access any /proc/ / directories, but their own. Sensitive files like cmdline, sched*, status are now protected against other users.
  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.

Linux kernel protection: Hiding processes from other users

Type the following mount command:
# mount -o remount,rw,hidepid=2 /proc
Edit /etc/fstab, enter:
# vi /etc/fstab
Update/append/modify proc entry as follows so that protection get enabled automatically at server boot-time:

 
proc    /proc    proc    defaults,hidepid=2     0     0
 

Save and close the file.

Linux demo: Prevent users from seeing processes that do not belong to them

In this example, I'm login as vivek@cbz-test:
$ ssh vivek@cbz-test
$ ps -ef
$ sudo -s
# mount -o remount,rw,hidepid=2 /proc
$ ps -ef
$ top
$ htop

Sample outputs:

Animated gif 01: hidepid in action

Animated gif 01: hidepid in action

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 monapp to group (say admin) that want to see process information and mount /proc as follows in /etc/fstab:

proc /proc proc defaults,hidepid=2,gid=admin 0 0 
References
TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 7 comments… read them below or add one }

1 Deny Dias August 21, 2014 at 9:46 pm

Hi! Thanks for the tip.

But the thing that really amazes me in your terminal tips is how you present these gif with recorded terminal sessions. How you do that?

Best, Deny.

Reply

2 Fabio Schmidt August 25, 2014 at 12:48 pm

Hi ! Firstly, congratulations for this outstanding tutorial, thanks for sharing !

If you could tell how you recorded the gif with your terminal session I would really appreciate !

Reply

3 anon August 27, 2014 at 5:22 am

Here’s one way to generate a gif from a terminal session:
http://wp.me/p2d5ln-4aq

Reply

4 Deny Dias August 27, 2014 at 9:57 am

Hi, anon!

Thanks for the tip. ttyrec and tty2gif are the ones I actually use today.

But the one we see here is kinda different. It shows a timer and nice cursor click warning circle that ttyrec/tty2gif doesn’t feature.

It appears to be a conventional screen recorder (X session, not tty related) set to record a specific area. I made some research on this matter and I could not find any screen recorder for Linux that features what we see on this gif above. I use SimpleScreenRecorder myself, but it definitively don’t have these two nice bells.

I would love to know what is the one used by Nix Craft, but they seem not willing to answer this…

Anyway, thank you very much.

Reply

5 George August 28, 2014 at 10:42 am

The tool is LICEcap

Reply

6 Deny Dias August 29, 2014 at 1:51 pm

Thank you very much, George!

Too bad LICEcap is a Windows/OS X only app though. No donuts for me or anyone under Linux/BSD. :(

Reply

7 test2 September 9, 2014 at 9:13 am

1) Try to using cgroup !

E.g. creating lxc-container for each user, similar to shared hosting, but virtual machines. Users will log-in to separate virtual machine cgroup-based, LXC. They will n’t able to read each others pids, and moreover they will have each own init(process) and all enviroment too.

2) Look at grsecurity solution, there is pack of patches, in this pack such solution like hide pids / processes infromation from other users is a light trick compare to other great hardening of linux kernel.

Anyway, your solution is better, looks like it is becoming native to Linux. Thanx!

Cheers!

Reply

Leave a Comment

Tagged as: , , , , ,

Previous Faq: