0

I am trying to call a python script from php (Using xamp).
The python script internally calls a shell script and the shell script has an ssh and scp command.
On executing the PHP back-end code using exec I observe the following errors in xamp log file.
The python script works fine through command line

Could not create directory '/sbin/.ssh'.^M
Failed to add the host to the list of known hosts          (/sbin/.ssh/known_hosts).^M
Permission denied, please try again.^M
Permission denied, please try again.^M
Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).^M
Could not create directory '/sbin/.ssh'.^M
Host key verification failed.^M
Veda
  • 7
  • 8

2 Answers2

0

Presumably, the python script is being run by a different user when it's called by PHP than when you run it by hand, which does not have appropriate permissions to do whatever actions the script is trying to perform. So you'll need to tweak permissions / user groups for the various things the script is going to be trying to do in order for it to run successfully.

Looking at this question is probably a good starting point:

How to check what user php is running as?

Once you identify the user that is actually running the script, you can try running the script as that user and then fixing problems as they come up.

Community
  • 1
  • 1
mrcheshire
  • 525
  • 2
  • 8
  • I have tried to modify the httpd.conf file and changed the user of apache to root .Also I tried to add apache user to sudoers file.Since security is not a major concern for me at this moment.But this also does not work @mrcheshire – Veda Dec 09 '15 at 23:26
0

I couldn't say for sure without seeing the Python script, but this probably has something to do with what the working directory is when the php user calls the script. You should either use absolute paths in your code or use

os.chdir(<path>)

to make sure you're using the correct working directory. Note if you do this, you'll probably run into permissions errors as mentioned in the other answer since .ssh and files in it are usually accessible only to the user whose directory it's in.

James J.
  • 216
  • 1
  • 5