help with php + ssh

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
vitid
Forum Newbie
Posts: 2
Joined: Sat Oct 25, 2008 12:30 pm

help with php + ssh

Post by vitid »

hi, i have problem about php using ssh

the problem is that i don't know how to respond to server's authentication request.

for example : i use grid-proxy-init command and server will request me to enter the passphrase key

(just to note that i didn't get a problem with login to server , i can login successfully but i don't know how to respond to server's request)

here is my code:

<?php


if(!($con = ssh2_connect("xxxxxxxxx", 22))){
echo "fail: unable to establish connection\n";
} else {

if(!ssh2_auth_password($con, "xxxx", "xxxxx")) {
echo "fail: unable to authenticate\n";
} else {

echo "okay: logged in...\n";



$cmd = 'grid-proxy-init -cert cert.pem -key userkey.pem';
//execute grid-proxy-init command and server will request me to type passphrase(password)
if(!($stream = ssh2_exec($con,$cmd)) ){
echo "fail: unable to execute command\n";
} else{
//here i can't get this to work , it act like i just login
//for example : if i type password = ls , it will display
//all file in directory ; instead of recognize it as passphrase
$stream = ssh2_exec($con,'password');
stream_set_blocking( $stream, true );

echo stream_get_contents($stream);

fclose($stream);

echo "success";
}


}
}
?>

i try googling for 3 hours and can't find any answer :(

very thank for your help and reply :) :)
Hannes2k
Forum Contributor
Posts: 102
Joined: Fri Oct 24, 2008 12:22 pm

Re: help with php + ssh

Post by Hannes2k »

Hi,
why doesn't ssh2_auth_password() work?
vitid
Forum Newbie
Posts: 2
Joined: Sat Oct 25, 2008 12:30 pm

Re: help with php + ssh

Post by vitid »

Hannes2k wrote:Hi,
why doesn't ssh2_auth_password() work?
no , i mean , i can login successfully , my problem is to answer the server request :
it request me to enter the passphrase(password) for grid-proxy-init command that i send

//execute grid-proxy-init command and server will request me to type passphrase(password)
if(!($stream = ssh2_exec($con,$cmd)) ){
echo "fail: unable to execute command\n";
} else{
//here i can't get this to work , it act like i just login
//for example : if i type password = ls , it will display
//all file in directory ; instead of recognize it as passphrase
$stream = ssh2_exec($con,'password');
Hannes2k
Forum Contributor
Posts: 102
Joined: Fri Oct 24, 2008 12:22 pm

Re: help with php + ssh

Post by Hannes2k »

Hi,
hmm one solution would be not to encrypt the key (userkey.pem), so grid-proxy-init don't ask you for the password of it.
Post Reply