note 76812 added to function.ssh2-auth-pubkey-file
| From: | tekiedude at gmail dot com | Date: | Tue, 31 Jul 2007 20:45:14 +0000 |
| Subject: | note 76812 added to function.ssh2-auth-pubkey-file | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-129083@lists.php.net to get a copy of this message | ||
This is probably incredibly insecure but if you are in a closed environment, you can run it at your
own risk.
I was trying to get ssh access from server A to server B but server A was running apache as
'apache' and
I needed files on server B that were owned by root. So I needed some way for the apache user to
connect
to server B as root. Here's what I did (both servers running linux - specifically CentOS4):
1. ssh-keygen -t rsa -f id_rsa generate with no passphrase
2. append the id_rsa.pub file to server B /root/.ssh/authorized_keys2
3. copy the id_rsa and id_rsa.pub files to a directory like /var/www/.ssh/
(happens to be apache's home dir on CentOS)
4. chown -R apache.apache /var/www/.ssh
Then you can connect like this:
$connection = ssh2_connect($server,22,array('hostkey'=>'ssh-rsa'));
if (ssh2_auth_pubkey_file($connection,'root',
'/var/www/.ssh/id_rsa.pub',
'/var/www/.ssh/id_rsa')) {
echo "success!";
}
else
{
echo "no success :-(";
}
----
Server IP: 69.147.83.197
Probable Submitter: 68.50.0.243
----
Manual Page -- http://www.php.net/manual/en/function.ssh2-auth-pubkey-file.php
Edit -- https://master.php.net/note/edit/76812
Del: integrated -- https://master.php.net/note/delete/76812/integrated
Del: useless -- https://master.php.net/note/delete/76812/useless
Del: bad code -- https://master.php.net/note/delete/76812/bad+code
Del: spam -- https://master.php.net/note/delete/76812/spam
Del: non-english -- https://master.php.net/note/delete/76812/non-english
Del: in docs -- https://master.php.net/note/delete/76812/in+docs
Del: other reasons-- https://master.php.net/note/delete/76812
Reject -- https://master.php.net/note/reject/76812
Search -- https://master.php.net/manage/user-notes.php