现象:
使用ps -aux
查看进程,发现进程属主不显示用户,而是现实用户id,如下:
[root@ba064483449d /]# ps -aux
Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.2 11460 1740 pts/0 Ss 05:20 0:00 /bin/bash
root 17 0.0 0.1 44076 1408 pts/0 S 05:21 0:00 su - justatest
500 18 0.0 0.2 11492 1728 pts/0 S+ 05:21 0:00 -bash
root 35 0.1 0.2 11492 1732 pts/1 Ss 05:42 0:00 /bin/bash
root 47 0.0 0.1 13368 1068 pts/1 R+ 05:43 0:00 ps -aux
解决:
发现这是linux本身机制问题在centos6有这个情况,当用户名称超过8个字符,系统会自动显示用户对应id。只要保证用户名称不超过8个字节即可避免这个现象
[test@ba064483449d ~]$ ps -aux
Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.2 11460 1740 pts/0 Ss 05:20 0:00 /bin/bash
root 17 0.0 0.1 44076 1408 pts/0 S 05:21 0:00 su - justatest
500 18 0.0 0.2 11492 1728 pts/0 S+ 05:21 0:00 -bash
root 35 0.0 0.2 11492 1732 pts/1 Ss 05:42 0:00 /bin/bash
root 53 0.0 0.1 44076 1404 pts/1 S 05:47 0:00 su - test
test 54 0.0 0.2 11492 1636 pts/1 S 05:47 0:00 -bash
test 69 0.0 0.1 13364 1064 pts/1 R+ 05:47 0:00 ps -aux
小结:
目前只测试过centos6和centos7,centos6超过8个字符会显示id,而centos7不会显示id,如下:
[justatestuser@Test01: ~] 13:49:56
$ ps -uax|grep sshd
root 954 0.0 0.0 112796 344 ? Ss May26 0:01 /usr/sbin/sshd -D
root 4231 0.0 0.7 157188 5868 ? Ss 11:49 0:00 sshd: root@pts/0
justate+ 5823 0.0 0.0 9088 664 pts/0 R+ 13:50 0:00 grep --color=auto sshd