Users
如何讓 ss 顯示正在使用套接字的使用者?
我想知道哪個使用者啟動了使用 TCP 套接字的程序。
我試過了
ss -nte
,但它只顯示uid,而不是使用者名。有沒有辦法ss
顯示使用者名?這裡的輸出ss -nte
lucio@debian:~$ ss -nte State Recv-Q Send-Q Local Address:Port Peer Address:Port ESTAB 0 0 192.168.56.1:45414 192.168.56.201:22 timer:(keepalive,46min,0) uid:1000 ino:711653 sk:4 <-> ESTAB 0 0 192.168.56.1:35544 192.168.56.203:22 timer:(keepalive,46min,0) uid:1000 ino:713505 sk:12 <-> ESTAB 0 0 192.168.178.70:55342 151.101.193.69:443 uid:1000 ino:758973 sk:3a <-> ESTAB 0 0 192.168.178.70:41212 198.252.206.25:443 timer:(keepalive,7min4sec,0) uid:1000 ino:756177 sk:3b <-> ESTAB 0 0 192.168.56.1:45542 192.168.56.202:22 timer:(keepalive,46min,0) uid:1000 ino:715991 sk:1e <-> ESTAB 0 0 192.168.178.70:41196 198.252.206.25:443 timer:(keepalive,6min19sec,0) uid:1000 ino:756063 sk:3c <-> ESTAB 0 0 192.168.178.70:43372 216.58.205.78:443 uid:1000 ino:759631 sk:3d <->
Hacky 試圖引入 perl 來提供幫助。看看它是如何
uid:1001
用user:bob
.# ss -ntel State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 10 0.0.0.0:12345 0.0.0.0:* uid:1001 ino:29109 sk:5e <-> LISTEN 0 100 127.0.0.1:25 0.0.0.0:* ino:18771 sk:2 <-> LISTEN 0 128 0.0.0.0:111 0.0.0.0:* ino:16606 sk:3 <-> LISTEN 0 128 0.0.0.0:22 0.0.0.0:* ino:20128 sk:4 <-> LISTEN 0 10 [::]:12345 [::]:* uid:1001 ino:29108 sk:61 v6only:1 <-> LISTEN 0 128 [::]:111 [::]:* ino:16609 sk:5 v6only:1 <-> LISTEN 0 128 *:80 *:* ino:18314 sk:6 v6only:0 <-> LISTEN 0 128 [::]:22 [::]:* ino:20130 sk:7 v6only:1 <-> # ss -ntel|perl -pne 'if(/uid:(\d+)/){@a=getpwuid($1);s/uid:(\d+)/user:$a[0]/}' State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 10 0.0.0.0:12345 0.0.0.0:* user:bob ino:29109 sk:5e <-> LISTEN 0 100 127.0.0.1:25 0.0.0.0:* ino:18771 sk:2 <-> LISTEN 0 128 0.0.0.0:111 0.0.0.0:* ino:16606 sk:3 <-> LISTEN 0 128 0.0.0.0:22 0.0.0.0:* ino:20128 sk:4 <-> LISTEN 0 10 [::]:12345 [::]:* user:bob ino:29108 sk:61 v6only:1 <-> LISTEN 0 128 [::]:111 [::]:* ino:16609 sk:5 v6only:1 <-> LISTEN 0 128 *:80 *:* ino:18314 sk:6 v6only:0 <-> LISTEN 0 128 [::]:22 [::]:* ino:20130 sk:7 v6only:1 <-> #
注意:我已經檢查了原始碼,似乎沒有任何原生的東西
ss
可以實現這一點。