Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #5343
| From | Jason Playne <jason@jasonplayne.com> |
|---|---|
| Newsgroups | comp.lang.php |
| Subject | Re: How to etablish an SSH2 tunnel with php ? |
| Date | 2012-04-04 01:36 -0700 |
| Organization | http://groups.google.com |
| Message-ID | <6978839.745.1333528606848.JavaMail.geo-discussion-forums@pbbnv8> (permalink) |
| References | <4f773369$0$6487$426a74cc@news.free.fr> |
On Sunday, April 1, 2012 12:40:09 AM UTC+8, Une Bévue wrote:
> The purpose is to query a remote PostgreSQL database via an ssh tunnel.
>
> If i do the tunnel "by hand" from terminal using :
> $ ssh -L 3333:localhost:5432 yt@iMac
>
> then, i can query a remote database :
> $host="localhost";
> $port=3333;
> $username='yt';
> $password='topsecret';
> $db = new PDO("pgsql:dbname=$dbname;host=$host;port=$port",
> $username, $password );
> $ret=$db->query('SELECT * FROM categories;');
> if($ret){
> while($row=$ret->fetch()){
> print_r($row);
> }
> }else{
> echo 'Error';
> }
>
> i've installes libssh2 for PHP on this computer, here is part of my
> info.php :
>
> SSH2 support enabled
> extension version 0.11.2
> libssh2 version 1.2.6
> banner SSH-2.0-libssh2_1.2.6
> remote forwarding enabled
> hostbased auth enabled
> polling support enabled
> publickey subsystem enabled
>
> however, even if i can "connect", authentification fail, either using
> password or keys...
>
> the code used :
> function connect_to($machine)
> {
> $connection=@ssh2_connect($machine, 22, array("hostkey"=>"ssh-dsa"));
> if(!$connection){
> echo "No connection.
> \n";
> return false;
> } else {
> echo "Connection établie.
> \n";
> }
>
> $fingerprint=@ssh2_fingerprint($connection, SSH2_FINGERPRINT_MD5 |
> SSH2_FINGERPRINT_HEX);
> echo "\$fingerprint = $fingerprint
> \n";
>
> /* Utilisation de public/private key */
> if(@ssh2_auth_pubkey_file($connection, "yt",
> '/home/yt/.ssh/id_dsa.pub', '/home/yt/.ssh/id_dsa',
> 'my -valid- passphrase')){
> echo "Authentification réussie.
> \n";
> return array($connection,$fingerprint);
> } else {
> echo "Échec de l'authentification.
> \n";
> return false;
> }
> }
>
> notice i get "Connection établie" and also the fingerprint.
>
> if after the print out of fingerprint i try a command i get nothing
> after an amout of time but without error :
> $stdout_stream=@ssh2_exec($connection, 'ls -al');
On Sunday, April 1, 2012 12:40:09 AM UTC+8, Une Bévue wrote:
> The purpose is to query a remote PostgreSQL database via an ssh tunnel.
>
> If i do the tunnel "by hand" from terminal using :
> $ ssh -L 3333:localhost:5432 yt@iMac
>
> then, i can query a remote database :
> $host="localhost";
> $port=3333;
> $username='yt';
> $password='topsecret';
> $db = new PDO("pgsql:dbname=$dbname;host=$host;port=$port",
> $username, $password );
> $ret=$db->query('SELECT * FROM categories;');
> if($ret){
> while($row=$ret->fetch()){
> print_r($row);
> }
> }else{
> echo 'Error';
> }
>
> i've installes libssh2 for PHP on this computer, here is part of my
> info.php :
>
> SSH2 support enabled
> extension version 0.11.2
> libssh2 version 1.2.6
> banner SSH-2.0-libssh2_1.2.6
> remote forwarding enabled
> hostbased auth enabled
> polling support enabled
> publickey subsystem enabled
>
> however, even if i can "connect", authentification fail, either using
> password or keys...
>
> the code used :
> function connect_to($machine)
> {
> $connection=@ssh2_connect($machine, 22, array("hostkey"=>"ssh-dsa"));
> if(!$connection){
> echo "No connection.
> \n";
> return false;
> } else {
> echo "Connection établie.
> \n";
> }
>
> $fingerprint=@ssh2_fingerprint($connection, SSH2_FINGERPRINT_MD5 |
> SSH2_FINGERPRINT_HEX);
> echo "\$fingerprint = $fingerprint
> \n";
>
> /* Utilisation de public/private key */
> if(@ssh2_auth_pubkey_file($connection, "yt",
> '/home/yt/.ssh/id_dsa.pub', '/home/yt/.ssh/id_dsa',
> 'my -valid- passphrase')){
> echo "Authentification réussie.
> \n";
> return array($connection,$fingerprint);
> } else {
> echo "Échec de l'authentification.
> \n";
> return false;
> }
> }
>
> notice i get "Connection établie" and also the fingerprint.
>
> if after the print out of fingerprint i try a command i get nothing
> after an amout of time but without error :
> $stdout_stream=@ssh2_exec($connection, 'ls -al');
On Sunday, April 1, 2012 12:40:09 AM UTC+8, Une Bévue wrote:
> The purpose is to query a remote PostgreSQL database via an ssh tunnel.
>
> If i do the tunnel "by hand" from terminal using :
> $ ssh -L 3333:localhost:5432 yt@iMac
>
> then, i can query a remote database :
> $host="localhost";
> $port=3333;
> $username='yt';
> $password='topsecret';
> $db = new PDO("pgsql:dbname=$dbname;host=$host;port=$port",
> $username, $password );
> $ret=$db->query('SELECT * FROM categories;');
> if($ret){
> while($row=$ret->fetch()){
> print_r($row);
> }
> }else{
> echo 'Error';
> }
>
> i've installes libssh2 for PHP on this computer, here is part of my
> info.php :
>
> SSH2 support enabled
> extension version 0.11.2
> libssh2 version 1.2.6
> banner SSH-2.0-libssh2_1.2.6
> remote forwarding enabled
> hostbased auth enabled
> polling support enabled
> publickey subsystem enabled
>
> however, even if i can "connect", authentification fail, either using
> password or keys...
>
> the code used :
> function connect_to($machine)
> {
> $connection=@ssh2_connect($machine, 22, array("hostkey"=>"ssh-dsa"));
> if(!$connection){
> echo "No connection.
> \n";
> return false;
> } else {
> echo "Connection établie.
> \n";
> }
>
> $fingerprint=@ssh2_fingerprint($connection, SSH2_FINGERPRINT_MD5 |
> SSH2_FINGERPRINT_HEX);
> echo "\$fingerprint = $fingerprint
> \n";
>
> /* Utilisation de public/private key */
> if(@ssh2_auth_pubkey_file($connection, "yt",
> '/home/yt/.ssh/id_dsa.pub', '/home/yt/.ssh/id_dsa',
> 'my -valid- passphrase')){
> echo "Authentification réussie.
> \n";
> return array($connection,$fingerprint);
> } else {
> echo "Échec de l'authentification.
> \n";
> return false;
> }
> }
>
> notice i get "Connection établie" and also the fingerprint.
>
> if after the print out of fingerprint i try a command i get nothing
> after an amout of time but without error :
> $stdout_stream=@ssh2_exec($connection, 'ls -al');
You can always generate a script to run on the remove server and run it over ssh.
e.g.
cat > /tmp/yarwoot1
#!/usr/bin/php
<?php
$sql = "select * from yar";
...
and then from your app
<?php
$out = shell_exec("ssh -iidentityfile user@host /tmp/yarwoot1");
// do something with $out here
Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
How to etablish an SSH2 tunnel with php ? Une Bévue <unbewusstsein@fai.invalid> - 2012-03-31 18:40 +0200
Re: How to etablish an SSH2 tunnel with php ? "Mr. B-o-B" <mr.chew.baka@gmail.com> - 2012-03-31 12:35 -0500
Re: How to etablish an SSH2 tunnel with php ? "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-04-01 00:56 +0200
Re: How to etablish an SSH2 tunnel with php ? Une Bévue <unbewusstsein@fai.invalid> - 2012-04-01 06:51 +0200
Re: How to etablish an SSH2 tunnel with php ? Jerry Stuckle <jstucklex@attglobal.net> - 2012-03-31 15:18 -0400
Re: How to etablish an SSH2 tunnel with php ? Une Bévue <unbewusstsein@fai.invalid> - 2012-04-01 07:03 +0200
Re: How to etablish an SSH2 tunnel with php ? Jerry Stuckle <jstucklex@attglobal.net> - 2012-04-01 10:00 -0400
Re: How to etablish an SSH2 tunnel with php ? Une Bévue <unbewusstsein@fai.invalid> - 2012-04-01 16:42 +0200
Re: How to etablish an SSH2 tunnel with php ? Jerry Stuckle <jstucklex@attglobal.net> - 2012-04-01 21:19 -0400
Re: How to etablish an SSH2 tunnel with php ? Une Bévue <unbewusstsein@fai.invalid> - 2012-04-02 08:26 +0200
Re: How to etablish an SSH2 tunnel with php ? Une Bévue <unbewusstsein@fai.invalid> - 2012-04-02 12:01 +0200
Re: How to etablish an SSH2 tunnel with php ? "Peter H. Coffin" <hellsop@ninehells.com> - 2012-04-02 07:15 -0500
Re: How to etablish an SSH2 tunnel with php ? Jerry Stuckle <jstucklex@attglobal.net> - 2012-04-02 09:04 -0400
Re: How to etablish an SSH2 tunnel with php ? "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-04-02 12:31 +0200
Re: How to etablish an SSH2 tunnel with php ? "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-04-02 12:54 +0200
Re: How to etablish an SSH2 tunnel with php ? Une Bévue <unbewusstsein@fai.invalid> - 2012-04-02 13:14 +0200
Re: How to etablish an SSH2 tunnel with php ? "Mr. B-o-B" <mr.chew.baka@gmail.com> - 2012-04-02 12:12 -0500
Re: How to etablish an SSH2 tunnel with php ? Une Bévue <unbewusstsein@fai.invalid> - 2012-04-02 13:12 +0200
Re: How to etablish an SSH2 tunnel with php ? Jason Playne <jason@jasonplayne.com> - 2012-04-04 01:36 -0700
Re: How to etablish an SSH2 tunnel with php ? unbewusst.sein@fai.invalid (Une Bévue) - 2012-04-05 07:36 +0200
Re: How to etablish an SSH2 tunnel with php ? Jerry Stuckle <jstucklex@attglobal.net> - 2012-04-05 08:10 -0400
csiph-web