http://themetricsystem.rjmetrics.com/2009/01/06/php-mysql-and-ssh-tunneling-port-forwarding/
I think this thread's approach of php-mysql-and-ssh-tunneling would work.
My question is about
Avoiding a password prompt: Normally, after issuing a command like the one above, you will receive a password prompt to validate the user logging into the remote machine. Again, this is bad for automation, since it’s never a good idea to have an application interacting with a command line prompt (or storing plain-text passwords). Public key encryption comes to the rescue again in this case. SSH won’t prompt for a password if the public certificate of remote user is stored in the ~/.ssh/authorized_keys file of the remote user account being logged into. We simply append our public key to this file and password prompts are no longer an issue.
So if my web site is running as user “apache”. I need to log in as user apache to generate keys and paste the key to the remote system authorized_keys file?
And if user apache’s home directory is in the var/www. I need to go to there to mkdir .ssh and then run the key generation command as user apache?
I don’t even remember that user apache has a password, I think the user apache is auto generated when I install the linux OS.
So I need to use sudo? Something like
mkdir /var/www/.ssh
chown -R apache:apache /var/www/.ssh
sudo -u apache ssh-keygen -t dsa
Am I right here?