linux – top仅显示当前用户进程

最近有一台运行CentOS 6.7的专用服务器,我们已经运行了更新,并注意到top只显示当前用户的进程.
[myuser@server2 ~]$top -b -n1 
top - 20:19:20 up 1 day,10:09,3 users,load average: 0.80,0.50,0.41
Tasks:  11 total,1 running,10 sleeping,0 stopped,0 zombie
cpu(s):  0.2%us,0.0%sy,0.0%ni,99.8%id,0.0%wa,0.0%hi,0.0%si,0.0%st
Mem:  32880988k total,26893324k used,5987664k free,140872k buffers
Swap:  1046520k total,0k used,1046520k free,19532120k cached

  PID USER      PR  NI  VIRT  RES  SHR S %cpu %MEM    TIME+  COMMAND               
 1648 myuser  20   0 98.8m 1020  688 S  0.0  0.0   0:00.00 man                   
 1651 myuser  20   0  103m 1184 1016 S  0.0  0.0   0:00.00 sh                    
 1652 myuser  20   0  103m  684  500 S  0.0  0.0   0:00.00 sh                    
 1656 myuser  20   0  103m  912  752 S  0.0  0.0   0:00.07 less                  
 3363 myuser  20   0  100m 1708  700 S  0.0  0.0   0:00.04 sshd                  
 3364 myuser  20   0  105m 1916 1524 S  0.0  0.0   0:00.00 bash                  
 8337 myuser  20   0 14940 1096  880 R  0.0  0.0   0:00.00 top                   
30429 myuser  20   0  100m 1696  696 S  0.0  0.0   0:00.16 sshd                  
30430 myuser  20   0  105m 1924 1536 S  0.0  0.0   0:00.01 bash                  
31132 myuser  20   0  100m 1692  692 S  0.0  0.0   0:00.05 sshd                  
31133 myuser  20   0  105m 1928 1536 S  0.0  0.0   0:00.04 bash

但是当使用sudo运行时,我会得到正常的输出

[myuser@server2 ~]$sudo top -bn1
top - 20:22:08 up 1 day,10:12,load average: 0.36,0.40,0.39
Tasks: 166 total,165 sleeping,26898188k used,5982800k free,141196k buffers
Swap:  1046520k total,19532188k cached

  PID USER      PR  NI  VIRT  RES  SHR S %cpu %MEM    TIME+  COMMAND               
32705 otherusr  20   0 21.9g 5.8g  15m S 39.8 18.3  28:47.76 java                  
    1 root      20   0 19280 1524 1232 S  0.0  0.0   0:00.76 init                  
    2 root      20   0     0    0    0 S  0.0  0.0   0:00.00 kthreadd              
    3 root      20   0     0    0    0 S  0.0  0.0   0:00.40 ksoftirqd/0           
    5 root       0 -20     0    0    0 S  0.0  0.0   0:00.00 kworker/0:0H          
    6 root      20   0     0    0    0 S  0.0  0.0   0:03.20 kworker/u16:0  
~~~~~omitted~~~~~

我试过在批处理模式下运行top并使用“u”& “U”并将其留空并按[enter],没有运气.

我很确定我正在运行真正的顶级,以绝对路径发射没有任何影响.

$which top
/usr/bin/top
$file /usr/bin/top
/usr/bin/top: ELF 64-bit LSB executable,x86-64,version 1 (SYSV),dynamically linked (uses shared libs),for GNU/Linux 2.6.18,stripped
$alias
alias l.='ls -d .* --color=auto'
alias ll='ls -l --color=auto'
alias ls='ls --color=auto'
alias vi='vim'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'

/ etc /中没有toprc

$ls -a /etc | grep -c toprc
0

proc安装如下

$sudo cat /proc/mounts | grep proc
none /proc proc rw,relatime 0 0
none /proc/sys/fs/binfmt_misc binfmt_misc rw,relatime 0 0
$sudo cat /etc/fstab | grep proc
proc        /proc   proc    defaults        0   0

关于Procs的更多细节

[myuser@server2 ~]$sudo -u otherusr ps -A
  PID TTY          TIME CMD
21921 pts/0    00:00:00 ps
32703 ?        00:00:00 screen
32705 pts/3    01:08:01 java
[myuser@server2 ~]$sudo ls -l /proc/ | grep 32705
dr-xr-x---  7 otherusr root     0 Sep 23 19:27 32705
[myuser@server2 ~]$sudo ls -l /proc/32705/ | grep stat
-r--------  1 otherusr root 0 Sep 23 21:54 mountstats
-r--r--r--  1 otherusr root 0 Sep 23 19:27 stat
-r--r--r--  1 otherusr root 0 Sep 23 19:27 statm
-r--r--r--  1 otherusr root 0 Sep 23 19:27 status
[myuser@server2 ~]$ls /proc/ | egrep "[0-9]{1,9}";
17363
17364
26124
26125
3363
3364
[myuser@server2 ~]$sudo -u otheruser ls /proc/ | egrep "[0-9]{1,9}"
26132
32703
32705
[myuser@server2 ~]$umask
0002
[root@server2 ~]# umask
0022

有任何想法吗?

解决方法

一种可能性是使用hidepid = 1或hidepid = 2安装/ proc.这个挂载选项在后来的Linux内核中添加,并在CentOS 5.9和6.3的某个时候重新移植.
Mount options
   The proc filesystem supports the following mount options:

   hidepid=n (since Linux 3.3)
          This option controls who can access the information in
          /proc/[pid] directories.  The argument,n,is one of the
          following values:

          0   Everybody may access all /proc/[pid] directories.  This is
              the Traditional behavior,and the default if this mount
              option is not specified.

          1   Users may not access files and subdirectories inside any
              /proc/[pid] directories but their own (the /proc/[pid]
              directories themselves remain visible).  Sensitive files
              such as /proc/[pid]/cmdline and /proc/[pid]/status are Now
              protected against other users.  This makes it impossible
              to learn whether any user is running a specific program
              (so long as the program doesn't otherwise reveal itself by
              its behavior).

          2   As for mode 1,but in addition the /proc/[pid] directories
              belonging to other users become invisible.  This means
              that /proc/[pid] entries can no longer be used to discover
              the PIDs on the system.  This doesn't hide the fact that a
              process with a specific PID value exists (it can be
              learned by other means,for example,by "kill -0 $PID"),but it hides a process's UID and GID,which Could
              otherwise be learned by employing stat(2) on a /proc/[pid]
              directory.  This greatly complicates an attacker's task of
              gathering information about running processes (e.g.,discovering whether some daemon is running with elevated
              privileges,whether another user is running some sensitive
              program,whether other users are running any program at
              all,and so on).

另一种可能性(由海报找到并作为参考信息添加到此答案中)是grsecurity,其具有将其他用户的进程从非特权用户隐藏的功能,作为其file system hardening的一部分.

Hide other users’ processes for unprivileged users

While the upstream kernel Now provides a mount option for /proc to hide other unprivileged users’ processes,grsecurity goes beyond this by hiding such information by default,hiding additional sources of sensitive information provided by the kernel in /proc,and hiding private network-related information of all users. Not only is the networking information a violation of the privacy of other users on the system,but it has also been useful in the past for TCP hijacking attacks.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


在Linux上编写运行C语言程序,经常会遇到程序崩溃、卡死等异常的情况。程序崩溃时最常见的就是程序运行终止,报告 Segmentation fault (core dumped) 错误。而程序卡死一般来源于代码逻辑的缺陷,导致了死循环、死锁等问题。总的来看,常见的程序异常问题一般可以分为 非法内存访
git使用小结很多人可能和我一样,起初对git是一无所知的。我也是因为一次偶然的机会接触到git,并被它强大的功能所蛰伏。git其实就是一种版本控制工具,就像svn一样,但是git是分布式的。我不想给git打广告,我们直入正题——git能帮我们做什么?1)源码版本控制。平常写一写demo程序可能和g
1. 操作系统环境、安装包准备 宿主机:Max OSX 10.10.5 虚拟机:Parallel Desktop 10.1.1 虚拟机操作系统:CentOS 7 x86_64 DVD 1511.iso Oracle:linux.x64_11gR2_database_1of2.zip linux.x6
因为业务系统需求,需要对web服务作nginx代理,在不断的尝试过程中,简单总结了一下常见的nginx代理配置。 1. 最简反向代理配置 在http节点下,使用upstream配置服务地址,使用server的location配置代理映射。 upstream my_server { server 10
Linux模块机制浅析 Linux允许用户通过插入模块,实现干预内核的目的。一直以来,对linux的模块机制都不够清晰,因此本文对内核模块的加载机制进行简单地分析。 模块的Hello World! 我们通过创建一个简单的模块进行测试。首先是源文件main.c和Makefile。 f...
一、Hadoop HA的Web页面访问 Hadoop开启HA后,会同时存在两个Master组件提供服务,其中正在使用的组件称为Active,另一个作为备份称为Standby,例如HDFS的NameNode、YARN 的ResourceManager。HDFS的web页面只有通过Active的Name
一个简单的通用Makefile实现Makefile是Linux下程序开发的自动化编译工具,一个好的Makefile应该准确的识别编译目标与源文件的依赖关系,并且有着高效的编译效率,即每次重新make时只需要处理那些修改过的文件即可。Makefile拥有很多复杂的功能,这里不可能也没必要一一介绍,为了
Linux内核源码分析方法一、内核源码之我见Linux内核代码的庞大令不少人“望而生畏”,也正因为如此,使得人们对Linux的了解仅处于泛泛的层次。如果想透析Linux,深入操作系统的本质,阅读内核源码是最有效的途径。我们都知道,想成为优秀的程序员,需要大量的实践和代码的编写。编程固然重要,但是往往
题记:自从接触到“跳板机”的概念后,一直就被烦不胜烦的机器名,ip地址,用户名,密码折腾的死去活来,心说能有个小精灵随时帮我输入那些重复的登录信息就好了。我见过最挫的方式就是用记事本把一堆机器的ip、登录用户、密码记录下来,每次登录机器就像是一场战斗:打开笔记本 勾选复制 写ssh命令 登录 再打开
统计一下你写过多少代码最近整理了一下自己从开始学习编程以来写过的程序和代码,林林总总,花了不少的时间,最后把一些自认为还算不错的代码提交到github上做一个简单的分类和备份。当然我并不奢求它们能成为多好的开源代码,只是希望通过这种方式分享自己的劳动成果罢了。如果大家有兴趣可以访问我的github,
一直以来被Linux的hostname和fqdn(Fully Qualified Domain Name)困惑了好久,今天专门抽时间把它们的使用细节弄清了。 一、设置hostname/fqdn
在Linux系统内设置hostname很简单,如: $ hostname florian 如果...
Linux的原子操作与同步机制 并发问题 现代操作系统支持多任务的并发,并发在提高计算资源利用率的同时也带来了资源竞争的问题。例如C语言语句“count++”在未经编译器优化时生成的汇编代码为。 当操作系统内存在多个进程同时执行这段代码时,就可能带来并发问题。 假设count变量初始值为0。进程1
最简git Server配置如何保持多台计算机的项目代码的同步更新呢?通过在一个公用计算机上开启git服务,任何能与该计算机互联的终端都可以同步最新的项目代码。每个终端所负责的就是下载代码更新,修改代码,提交代码更新,这些工作产生的变化能全部反应到git服务器上。同时,这么做也能避免使用github
建议收藏!!!Linux 服务器必备的安全设置~
QQ 用 Electron 重构后,终实现 Linux、macOS、Windows 三端架构统一!
Shell 分析日志文件高效命令,超级好用!
Linux下的Docker容器网络:如何设置容器间的网络连接和通信?
Linux 服务器必备的安全设置,建议收藏!!!
以为很熟悉 Linux,万万没想到在生产环境翻车了.....
Linux 或 Windows 上实现端口映射