How To Execute SSH Commands Via PHP
I am looking to SSH out via PHP. What is the best/most secure way to go about this? I know I can do: shell_exec("SSH user@host.com mkdir /testing"); Anything better? That feels so 'naughty' :). I would use phpseclib, a pure PHP SSH implementation . An example: <?php include('Net/SSH2.php'); $ssh = new Net_SSH2('www.domain.tld'); if (!$ssh->login('username', 'password')) { exit('Login Failed'); } echo $ssh->exec('pwd'); echo $ssh->exec('ls -la'); ?> Do you have the SSH2 extension available? Docs: http://www.php.net/manual/en/function.ssh2-exec.php $connection = ssh2_connect('shell.example.com',