/proc/net/wireless does not show values unless run as root

procsudowifi

cat /proc/net/wireless does not show statistics for wireless devices unless it is run as root, even though the permissions on the file are 444. The same seems to apply when accessing statistics via iwlib. Is there a way to cat this file and see the values without requiring the command be run as root?

Best Answer

I came across this issue yesterday and found two methods:

1. Sudoers

Add a rule allowing the command access without a password.

# visudo

Replacing username:

...
username ALL=(ALL) NOPASSWD: /bin/cat /proc/net/wireless
...

Some downsides include auth log pollution, especially if checking signal every few seconds, as well as the need to add sudo to these scripts.

2. Capabilities

Give the binary CAP_NET_ADMIN

# setcap cap_net_admin+ep /bin/cat

+ to add and - to remove

  • e: Effective - This means the capability is “activated”.
  • p: Permitted - This means the capability can be used/is allowed.
  • i: Inherited - The capability is kept by child/subprocesses upon execve() for example.

More info at man cap_from_text

Disclaimer: CAP_NET_ADMIN is a form of elevated privilege. Allowing harm to things like network configuration and firewalls. In my case I only need it for grep used in an i3 blocklet. I am not sure myself what the risk is in this case and would appreciate commentary.

Related Question