1

As per this: https://linux.die.net/man/8/iwlist I understand that scanning of WiFi Networks requires root access. If you are a regular user than you can only see the Wifi Network you are connected with. Lets go into my problem...

As a regular user when I use this command in terminal:

iwlist wlan0 scan|grep "Frequency\|Quality\|ESSID"

Then my output is this:

Frequency:2.417 GHz (Channel 2)
Quality=67/70  Signal level=-43 dBm  
ESSID:"My-WiFi"

That is the network I am currently connected to (My-WiFi)

When I run this command in terminal as sudo:

sudo iwlist wlan0 scan|grep "Frequency\|Quality\|ESSID"

Then my output is this:

Frequency:2.417 GHz (Channel 2)
Quality=69/70  Signal level=-41 dBm  
ESSID:"My-WiFi"
Frequency:2.412 GHz (Channel 1)
Quality=43/70  Signal level=-67 dBm  
ESSID:"MySpectrumWiFi54-2G"
Frequency:2.412 GHz (Channel 1)
Quality=61/70  Signal level=-49 dBm  
ESSID:"MySpectrumWiFif4-2G"
Frequency:2.427 GHz (Channel 4)
Quality=36/70  Signal level=-74 dBm  
ESSID:"MyCharterWiFieb-2G

My problem is that I need to scan the WiFi networks without a normal user having sudo access.

How can I change permissions to run iwlist wlan0 scan|grep "Frequency\|Quality\|ESSID" to show the sudo output, but without using sudo or having root access?

2
  • Go it working. The test user is bob so I used the command sudo visudo and at the end of the file I put in this line bob ALL=NOPASSWD:/sbin/iwlist Now when I am on the user bob I can use sudo iwlist wlan0 scan|grep "Frequency\|Quality\|ESSID" without the system asking me for password. Other sudo commands are still protected.
    – Joe Elia
    Commented Aug 7, 2019 at 23:58
  • If you solved it, then enter your answer as an answer rather than a comment.
    – Brick
    Commented Aug 8, 2019 at 2:16

1 Answer 1

1

Your "solution" is the sledgehammer approach.

Editing the sudoers file is not recommended. If you really want to do so it is safer to make a new entry in /etc/sudoers.d (which is used to give user pi passwordless sudo)

If you want all users to be able to run a command setting suid permission is more normal.

sudo chmod a+s /sbin/iwlist
1
  • This is the correct answer because unlike /etc/sudoers (file that opens with sudo visudo command), the contents of /etc/sudoers.d survives system upgrades, so it's preferable to create a file there than to modify /etc/sudoers.
    – Joe Elia
    Commented Aug 8, 2019 at 4:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.