Ocultar suas informações de usuário
Portanto, com top
, seu comportamento padrão é mostrar todos os processos na caixa e você não pode realmente impedir que outros usuários vejam esses detalhes. Os métodos para fazer isso são discutidos neste documento sobre o assunto:
- Como tornar um processo invisível para outros usuários ?
- Ocultar os processos do Linux para se divertir e lucrar
- É possível" esconder "um processo da listagem de
ps
outop
no Linux
O terceiro link mostra um método interessante que é um patch de kernel que adicionou uma opção chamada hidepid
to mount
nos kernels Linux 3.3 +:
$ mount /proc -o remount,hidepid=2
hidepid=0 (default) means the old behavior - anybody may read all world-readable /proc/PID/* files.
hidepid=1 means users may not access any /proc// directories, but their own. Sensitive files like cmdline, sched*, status are now protected against other users. As permission checking done in proc_pid_permission() and files' permissions are left untouched, programs expecting specific files' modes are not confused.
hidepid=2 means hidepid=1 plus all /proc/PID/ will be invisible to other users. It doesn't mean that it hides whether a process exists (it can be learned by other means, e.g. by kill -0 $PID), but it hides process' euid and egid. 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.
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.
NOTE: This doesn't give you any ability to control visibility, only restrict users to see their details under
/proc
.
Escondendo informações de outros usuários
Se você quiser ocultar outros usuários quando estiver usando top
, poderá fazer assim:
$ top -u '!root'
...
top - 00:04:16 up 2 days, 1:51, 1 user, load average: 0.00, 0.01, 0.05
Tasks: 80 total, 1 running, 79 sleeping, 0 stopped, 0 zombie
%Cpu(s): 0.0 us, 0.3 sy, 0.0 ni, 99.7 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
KiB Mem : 1016156 total, 204212 free, 80104 used, 731840 buff/cache
KiB Swap: 2097148 total, 2097148 free, 0 used. 755224 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
597 dbus 20 0 26668 1924 1364 S 0.0 0.2 0:08.55 dbus-daemon
633 polkitd 20 0 536264 10216 4796 S 0.0 1.0 0:00.35 polkitd
634 libstor+ 20 0 8576 816 668 S 0.0 0.1 0:00.49 lsmd
1305 postfix 20 0 91956 4292 3232 S 0.0 0.4 0:00.09 qmgr
4199 vagrant 20 0 152392 3020 1424 S 0.0 0.3 0:01.53 sshd
4200 vagrant 20 0 116196 2928 1796 S 0.0 0.3 0:00.05 bash
5622 postfix 20 0 91776 4044 3028 S 0.0 0.4 0:00.00 pickup
5672 user1 20 0 116096 2864 1808 S 0.0 0.3 0:00.04 bash
5758 user1 20 0 157624 2136 1544 R 0.0 0.2 0:00.00 top
A notação, '!root'
significa que não mostra o usuário root.