How to call shell script from php that requires SUDO?
Edit the sudoers file (with visudo) and add a rule that allows the web server user to run the command without a password. For example: www-data ALL=NOPASSWD: /path/to/script
Edit the sudoers file (with visudo) and add a rule that allows the web server user to run the command without a password. For example: www-data ALL=NOPASSWD: /path/to/script
Use tee –append or tee -a. echo ‘deb blah … blah’ | sudo tee -a /etc/apt/sources.list Make sure to avoid quotes inside quotes. To avoid printing data back to the console, redirect the output to /dev/null. echo ‘deb blah … blah’ | sudo tee -a /etc/apt/sources.list > /dev/null Remember about the (-a/–append) flag! Just tee … Read more
For sudo there is a -S option for accepting the password from standard input. Here is the man entry: -S The -S (stdin) option causes sudo to read the password from the standard input instead of the terminal device. This will allow you to run a command like: echo myPassword | sudo -S ls /tmp … Read more
Use a virtual environment: $ virtualenv myenv .. some output .. $ source myenv/bin/activate (myenv) $ pip install what-i-want You only use sudo or elevated permissions when you want to install stuff for the global, system-wide Python installation. It is best to use a virtual environment which isolates packages for you. That way you can … Read more
It sounds like you need to set up passwordless sudo. Try: %admin ALL=(ALL) NOPASSWD: osascript myscript.scpt Also comment out the following line (in /etc/sudoers via visudo), if it is there: Defaults requiretty
This seemed to work for me sudo -i which takes on the non-sudo PATH
When you run pip with sudo, you run setup.py with sudo. In other words, you run arbitrary Python code from the Internet as root. If someone puts up a malicious project on PyPI and you install it, you give an attacker root access to your machine. Prior to some recent fixes to pip and PyPI, … Read more
Granting the user to use that command without prompting for password should resolve the problem. First open a shell console and type: sudo visudo Then edit that file to add to the very end: username ALL = NOPASSWD: /fullpath/to/command, /fullpath/to/othercommand eg john ALL = NOPASSWD: /sbin/poweroff, /sbin/start, /sbin/stop will allow user john to sudo poweroff, … Read more
Your command does not work because the redirection is performed by your shell which does not have the permission to write to /root/test.out. The redirection of the output is not performed by sudo. There are multiple solutions: Run a shell with sudo and give the command to it by using the -c option: sudo sh … Read more
First you need to export HTTP_PROXY. Second, you need to read man sudo carefully, and pay attention to the -E flag. This works: $ export HTTP_PROXY=foof $ sudo -E bash -c ‘echo $HTTP_PROXY’ Here is the quote from the man page: -E, –preserve-env Indicates to the security policy that the user wishes to preserve their … Read more