remcohaszing / pywakeonlan

A small python module for wake on lan.
https://pywakeonlan.readthedocs.io
MIT License
281 stars 68 forks source link

Permissions issue on Raspberry Pi OS #20

Closed Lax4ever closed 1 year ago

Lax4ever commented 3 years ago

Trying to utilize a Raspberry Pi 4 as a wake on lan hub for other devices on my network. The following script works via Windows and via Ubuntu Server 18.04 but not via Raspian Buster.

from wakeonlan import send_magic_packet;

def wakeup():
    send_magic_packet('_MAC_', ip_address='_subnet_.255', port=9)

if __name__ == "__main__":
    wakeup()

When used on Raspbian, a permissions error occurs:

Traceback (most recent call last):
  File "foo.py", line 7, in <module>
    wakeup()
  File "foo.py", line 4, in wakeup
    send_magic_packet('_MAC_', ip_address='_subnet_.255', port=9)
  File "/usr/local/lib/python3.7/dist-packages/wakeonlan.py", line 58, in send_magic_packet
    sock.send(packet)
PermissionError: [Errno 1] Operation not permitted

As you can see this is running via Python 3, I have tried running the script with sudo with the same results. Running it through an elevated Python 3 shell produces no error but also no result.

I am not sure how to resolve since it works on Ubuntu Server and Windows. Any advice would be appreciated.

ericfrey commented 2 years ago

On a raspberry pi running Raspbian 10 wakeonlan works for me if the user is a member of the netdev group. This is on a raspberry pi model 4 using the built-in ethernet. It is not working for me when I use a USB ethernet interface. This is true even when I specify the ip address of the target and that would have to be routed out the USB interface. (I see that there is a pull request that enables specifying the NIC, but haven't tried it yet). Note that the etherwake command from the etherwake package does work. It requires that the command be run with root privileges. I handled that by taking away read and execute permissions from other, changing the group to netdev, and making the command setuid root

chmod o= /usr/sbin/etherwake
chgrp  netdev /usr/sbin/etherwake
chmod u+s /usr/sbin/etherwake

(The order of the commands matters because chgrp resets the setuid bit.) Then users in the netdev group can wake things using etherwake. From what I understand, on Linux this is not a big security issue, but it could be on other systems).

remcohaszing commented 2 years ago

@Lax4ever does that answer your question?

remcohaszing commented 1 year ago

I’m closing this issue, as it’s not actionable for this repository.