Its been a while since last I've posted anything but am here trying to keep up with many websites. Any who, Recently I was requested by one of my clients to create a web interface to help the none technical restart apache, mysql and do some monitoring on different servers.
so, first what I did is generate a key to create secure channels between the servers in order to connect without prompting for password (click here for steps). Then, I faced some trouble writing the PHP code which will connect and do these tasks and after long day of surfing and some help from my team (Basant) we finally nailed it.
First, you will need to install openssl (openssl-devel), then download and compile libssh2 and then you will need to add the extension in your PHP.ini (click here for PHP ssh2 installation manual) and here is a sample code on how it can be done in PHP.
// Notify user if the server terminates the connection function my_ssh_disconnect($reason, $message, $language) { message: %s\n" ,$reason, $message); } 'kex' => 'diffie-hellman-group1-sha1', 'crypt' => '3des-cbc', 'comp' => 'none'), 'crypt' => 'aes256-cbc,aes192-cbc,aes128-cbc', 'comp' => 'none')); $connection = ssh2_connect('domain_name.com', 22, $methods, if (ssh2_auth_password($connection, 'linux_user', 'linux_password')) { echo "Authentication Successful!\n\n"; // fwrite will send execute commands and return value in $shell // this will look the $shell array and print the returned value. } }else{ echo "Error with connection\n"; } ?>
Loading ...
Recent Comments