2

I have a shellscript with connects to a a different machine with ssh and a key so it does not need the username and password.

When i run this script from commandline it works fine.. but when I run this script from php shell_exec it does not work.

If I make an ssh connection with PHP and run the script as my own user it does work.

Now for my question :D Is there a way to just running the script in shell_exec from php without making an connection over ssh as a different user?

3
  • 1
    That's a quite poor description of you scenario. Anyway, are you sure that the commandline and the PHP use the same user, i.e. you are running the PHP from the commandline and not from a webserver? Commented Nov 8, 2010 at 10:48
  • This sounds more like a sysadmin question. If the user PHP runs under has the right to execute the program in question, it is possible. Otherwise, it is not possible. Commented Nov 8, 2010 at 10:56
  • Php runs as www-data and when i connect to ssh under php I login under my own user account so definitly not the same user. Where it goes wrong is in the shellscript... ssh -n -i $KEYFILE $USER@$HOST "bash ./jpg2xml.sh /tmp/$tmpfile | ./ocr" which is run from the shellscript by php. It does run the script, only this part that is not working! Commented Nov 8, 2010 at 11:11

3 Answers 3

1

Did you specify the private key file correctly?

Sign up to request clarification or add additional context in comments.

1 Comment

Arrr you are right good sir.. if i change the owner to www-data it works.. it was not readable for apache.
0

If you are using Ubuntu or Debian the web server is running with the user name www-data. For other systems please check the web server configuration for the user name. You can simply test if this user (and your php web application) is able to do the SSH connection.

1) Become the user of your web server

sudo su www-data

2) Try connecting the remote host

ssh remoteUser@remoteHost

If you will get connected without entering a password there must be a different problem. If you have to enter a password, the key files were stored for a different user - not for www-data. You have already configured SSH to use the key. Do the same for your local user www-data and it will work.

1 Comment

But I connect in the shellscript as a different user then www-data so in theory it should not make a difference right? I do the following.. ssh -o StrictHostKeyChecking=no -n -i $KEYFILE $USER@$HOST
0

It seems ssh connection does not work with shell_exec. If i run the shellscript under ssh2_exec it does seem to work.

Which is a little strange as the ssh connection is made in the script file with a public and private key.. I would assume this would just run :s

The webserver is allowed to execute the file, as there are other command in there who work as expected.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.