0

I'm trying to execute route add command with PHP this way: exec("/sbin/route -net 127.0.0.1", $output); and I'm getting SIOCADDRT operation not permitted. I suppose this is because I don't execute the route command through sudo. But I can't do sudo from php because the command asks for the su password. So how can I run route add without sudo?

Thanks!

VladN
  • 729
  • 1
  • 10
  • 29

2 Answers2

1

The best way to do this is, IMHO, is to create a shell script which use this command. After that, allow this shell script to be executed as root in /etc/sudoers.

The syntax to add in sudoers file can be found in this question's accepted answer.

So you just need to:

exec("/usr/bin/sudo /path/to/script");

This way, your root password is not exposed and you can add any command you'd like in your script.

Community
  • 1
  • 1
gustavotkg
  • 4,099
  • 1
  • 19
  • 29
0

You can send set sudo to get password from standard input using -S argument

exec("echo 'password' | sudo -u root -S /sbin/route -net 127.0.0.1", $output);
Ivan
  • 3,567
  • 17
  • 25