phprsh

Executing RSH command using exec() in PHP


I am having trouble using rsh in the PHP exec() command. The error that I'm getting is: Could not create directory '/nonexistent/.ssh'.

It appears that this is because Apache runs as the user nobody who does not have a home directory, therefore it cannot find/create a .ssh directory. What I would do from the terminal is something similar to:

sudo su - user_with_home_directory
/usr/bin/rsh -n -l username myserver.com /path/to/my/script.sh

But I am not aware of how to do this using PHP's exec() command. I don't want to (and cannot) give the nobody user a home directory just to get the problem to go away.

Any help is greatly appreciated to helping me figure out how to get this to work.


Solution

  • So it seems as if the rsh on the server that I'm using is Kerberos enabled, which in turn uses SSH to do the authentication. This is what was causing the search for a .ssh directory.

    To solve this, I created an SSH key and stored it on the filesystem at a different location other than the .ssh directory, again to prevent from creating a home directory for the nobody user. Then using SSH, I specified the -i option that points to my generated SSH key, allowing me to execute the script remotely without the need to login with a password.