note 79754 added to ref.ssh2

From: Date: Tue, 11 Dec 2007 13:41:26 +0000
Subject: note 79754 added to ref.ssh2
Groups: php.notes 
Request: Send a blank email to php-notes+get-133364@lists.php.net to get a copy of this message
Setup PHP SSH2 Connection from php running locally win32 to a remote box (i used pair networks) 1. Download module http://www.php.net/downloads.php Download Win32 binaries and extract php_ssh2.dll to the extensions directory Edit the php.ini file that is being used to include this extension extension=php_ssh2.dll Generate a pub / private key pair on the server you wish to connect to ssh-keygen -t rsa -C "username@boxname.pair.com" Generating public/private rsa key pair. Enter file in which to save the key (/usr/home/username/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /usr/home/username/.ssh/id_rsa. Your public key has been saved in /usr/home/username/.ssh/id_rsa.pub. Copy both the public and private key files to your local box. Cut and paste the id_rsa.pub contents into authorized_keys2 file in /usr/home/username/.ssh - creating it if it does not exist. Create a php program containing the following <?php /* Notify the user if the server terminates the connection */ function my_ssh_disconnect($reason, $message, $language) { printf("Server disconnected with reason code [%d] and message: %s\n", $reason, $message); } $methods = array( 'kex' => 'diffie-hellman-group1-sha1,diffie-hellman-group14-sha1,' .'diffie-hellman-group-exchange-sha1', 'client_to_server' => array( 'crypt' => '3des-cbc', 'comp' => 'none'), 'hostkey'=>'ssh-rsa', 'server_to_client' => array( 'crypt' => 'aes256-cbc,aes192-cbc,aes128-cbc', 'comp' => 'none')); $callbacks = array('disconnect' => 'my_ssh_disconnect'); $connection = ssh2_connect('vepar.pair.com', 22, $methods, $callbacks); if (!$connection) die('Connection failed'); /* Uncomment to secure even further, you want to get the known host key by getting $fingerprint the first time and then hard coding $known_host = ''; $fingerprint = ssh2_fingerprint($connection, SSH2_FINGERPRINT_MD5 | SSH2_FINGERPRINT_HEX); if ($fingerprint != $known_host) { die("HOSTKEY MISMATCH!\n" . "Possible Man-In-The-Middle Attack? $fingerprint"); } */ if (ssh2_auth_pubkey_file($connection, 'username', 'S:/sshphp/id_rsa.pub', 'S:/sshphp/id_rsa', '')) { echo "Public Key Authentication Successful\n"; } else { die('Public Key Authentication Failed'); } ?> Alan Reddan Silverarm ---- Server IP: 212.108.64.191 Probable Submitter: 87.198.162.211 ---- Manual Page -- http://www.php.net/manual/en/ref.ssh2.php Edit -- https://master.php.net/note/edit/79754 Del: integrated -- https://master.php.net/note/delete/79754/integrated Del: useless -- https://master.php.net/note/delete/79754/useless Del: bad code -- https://master.php.net/note/delete/79754/bad+code Del: spam -- https://master.php.net/note/delete/79754/spam Del: non-english -- https://master.php.net/note/delete/79754/non-english Del: in docs -- https://master.php.net/note/delete/79754/in+docs Del: other reasons-- https://master.php.net/note/delete/79754 Reject -- https://master.php.net/note/reject/79754 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#133364) next »