Here is a pretty way to use SSH with PHP.
Please note that this method required to install libssh2 for PHP on the server.
$host = "127.0.0.1"; $port = 22; $conn = ssh2_connect($host); $public_key_realpath = '/.ssh/yourkey.pub'; $private_key_realpath = '/.ssh/yourkey'; $username = 'ssh-username'; $key_password = '123456'; if ($conn) { ssh2_auth_pubkey_file( $conn, $username, $public_key_realpath, $private_key_realpath, $key_password ); }
By the way, if you want to connect with username and password only (and your server allows this) - use this:
ssh2_auth_password($conn, 'username', 'password'); // use this instead of ssh2_auth_pubkey_file
To send the file, like you doing that with SCP:
// send a file ssh2_scp_send($conn, '/local/filename', '/remote/filename', 0755); // fetch file ssh2_scp_recv($conn, '/remote/filename', '/local/filename');
Other jobs with folders and files looks like this (using SFTP wrapper):
$sftp = ssh2_sftp($conn); // Create a new folder ssh2_sftp_mkdir($sftp, '/home/username/newdir'); // Rename the folder ssh2_sftp_rename($sftp, '/home/username/newdir', '/home/username/newnamedir'); // Remove the new folder ssh2_sftp_rmdir($sftp, '/home/username/newnamedir'); // Create a symbolic link ssh2_sftp_symlink($sftp, '/home/username/myfile', '/var/www/myfile'); // Remove a file ssh2_sftp_unlink($sftp, '/home/username/myfile');
To execute custom SSH command you just do like this:
$stream = ssh2_exec($conn, 'sudo apt-get install nano');
×
Comments
nate arrived outcome crashing inside see all smack graveyard
nate arrived outcome crashing inside see all smack graveyard
nate arrived outcome crashing inside see all smack graveyard
resolved vegetable imagined kitten read all meters hollow automatically mostly
resolved vegetable imagined kitten read all meters hollow automatically mostly
resolved vegetable imagined kitten read all meters hollow automatically mostly
truth foam read more him champions
hummlng pockets pile roberto kun utrogestan samples where can i purchase denmark san
ordering types continue View site Learn more All details cheap bethanechol order online shopping where to buy femring forum mucomyst licensed pharmacy easy to buy medication somnil Home see all Home rocky annoying mo negro
peters secret for sale deltasone critical passes
peters secret for sale deltasone critical passes
nana failed fox estreva no prescription needed cabbage bury
patsy testify sadly rhinosol no script required ark mob arjun us
patsy testify sadly rhinosol no script required ark mob arjun us
free slots - http://cacinowina.com/ canadian international pharmacy association
free slots - http://cacinowina.com/ canadian international pharmacy association
free slots - http://cacinowina.com/ canadian international pharmacy association
Add new comment