1

I'm trying to use wakeonlan to send a magic packet. However, It only works if I use sudo:

sudo wakeonlan xx:xx:xx:xx:xx:xx

When I don't use sudo the output says the magic packet has sent, but the server never wakes up. Is there a way to run this command without sudo? I need to do so in order to run the command in a php script. Thanks!

2 Answers2

1

There are a few ways to use sudo from php as this article relates:

Before doing this remember the article's warning:

Giving sudo to PHP is one of the several ways to execute a shell command from a web interface. It is probably not one of the most secure methods, so I recommend not doing this on a server which has outside (WAN) internet access because of the possibility of malicious code being executed. A person with ill intent could then access your entire network, including any shared files, network attached storage, etc. You need to be careful with this.

Add user to /etc/sudoers file

The article above describes how to setup a user with sudo access not needing a password. This Q&A gives other examples:

0

You can add cap_net_raw+ep to the program so it doesn't require sudo. This will also not run the command as root. It permits it to generate arbitrary network packages.

sudo ln -s /usr/sbin/etherwake /usr/bin/etherwake
sudo setcap cap_net_raw+ep /usr/sbin/etherwake

This option might not be available on all systems. Allowing sudo on certain programs without passwords may open up privilege escalation vectors. Abusing raw package generation is a bit harder.

FalcoGer
  • 865