Hello,

I have a small problem, I am triing to execute a script which will be used to update files on several remote computers with PHP. The script works fine when called from a usual Linux account. However when I run the script from a PHP script using system. I get an error saying cant create //.ssh dir
...
blah
blah
...
lost connection

So my question is how are these scripts executed, and how can I set permissions, keygen etc etc to have this script execute properly from the PHP.

Thanks,

Pete.

    your scp command looks for a .ssh directory in your home directory, if not found it is created. this dir will store the keys and stuff.

    however, you php script is executed, probably via apache i presume, under the user nobody.

    on a redhat system, nobody's home is /. in which it cannot write.

    You should create a .ssh directory in your / dir and apply proper permissions for the nobody user to read/write from it.

      9 years later

      It's amazing that 9 years later, this solution still applies.

      I was attempting to use scp, under PHP/Apache, to copy a file from a remote file server to the Web server with public key authentication (no passwords were to be used).

      Even thought I had configured public key authentication properly (my command worked fine from within PuTTY), my command was failing when executed via the Web server because SSH (via scp's invocation) was looking for a /var/www/.ssh directory; the problem was apparent by examining the verbose output of the scp command. SSH wanted to create the directory, because PHP was spawning the scp process under the "apache" user (whose home directory is /var/www).

      Once I had taken the following steps

      $ mkdir /var/www/.ssh
      $ chown apache:apache /var/www/.ssh
      $ chmod 700 /var/www/.ssh
      

      I placed an appropriate "known_hosts" file inside the directory and everything functioned as expected.

      Thanks, anonymous user!

        Write a Reply...