How to get rid of “..you would have to be root to see it all” when running netstat as normal user

Run netstat as a normal user, you will see this warning below.

    $ netstat -tupln | grep ':22'
    (Not all processes could be identified, non-owned process info
     will not be shown, you would have to be root to see it all.)
    tcp        0      0 127.0.0.1:2208              0.0.0.0:*                   LISTEN      -
    tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      -
    tcp        0      0 127.0.0.1:2207              0.0.0.0:*                   LISTEN      -
    tcp        0      0 :::22                       :::*                        LISTEN      -

To get rid of this, redirect the error to /dev/null.

    $ netstat -tupln 2> /dev/null | grep ':22'
    tcp        0      0 127.0.0.1:2208              0.0.0.0:*                   LISTEN      -
    tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      -
    tcp        0      0 127.0.0.1:2207              0.0.0.0:*                   LISTEN      -
    tcp        0      0 :::22                       :::*                        LISTEN      -

We can also use lsof instead. But note it will show only ports opened by processes the user owns. These are my stale ssh sessions.

    $ /usr/sbin/lsof -i tcp:22
    COMMAND   PID   USER   FD   TYPE   DEVICE SIZE/OFF NODE NAME
    ssh     30509 rtfmp    3u  IPv4 47470860      0t0  TCP rtfmp.example.com:55318->remote.example.com:ssh (ESTABLISHED)
    ssh     30945 rtfmp    3u  IPv4 80858419      0t0  TCP rtfmp.example.com:57454->remote2.example.com:ssh (ESTABLISHED)
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s