LoginSignup
2
1

More than 3 years have passed since last update.

netstat(ss) -pでポートを掴んでいるプロセス名・PIDを出すにはroot権限で実行する必要がある

Last updated at Posted at 2019-06-08

タイトルが全てです。当たり前みたいな話ではあるものの気づくのに手間取ったので備忘録。

検証環境

OS : CentOS 7.6 (VagrantでVirtualBOX上に構築)

[vagrant@localhost ~]$ uname -a
Linux localhost.localdomain 3.10.0-957.5.1.el7.x86_64 #1 SMP Fri Feb 1 14:54:57 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
[vagrant@localhost ~]$ cat /etc/redhat-release 
CentOS Linux release 7.6.1810 (Core) 
[vagrant@localhost ~]$ ss --version
ss utility, iproute2-ss170501

実際に打ってみる

CentOS 7系なのでnetstatではなくssです。

[vagrant@localhost ~]$ ss -t # sudoなし、pオプションなし => 当然PIDは表示されない
State      Recv-Q Send-Q      Local Address:Port                       Peer Address:Port                
ESTAB      0      0               10.0.2.15:ssh                            10.0.2.2:51063                
[vagrant@localhost ~]$ ss -tp # sudoなし、pオプションあり => 表示されない
State      Recv-Q Send-Q      Local Address:Port                       Peer Address:Port                
ESTAB      0      0               10.0.2.15:ssh                            10.0.2.2:51063                
[vagrant@localhost ~]$ sudo ss -tp # sudoあり、pオプションあり => 表示される
State      Recv-Q Send-Q      Local Address:Port                       Peer Address:Port                
ESTAB      0      0               10.0.2.15:ssh                            10.0.2.2:51063                 users:(("sshd",pid=6039,fd=3),("sshd",pid=6036,fd=3))
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1